复习题
           
C程序设计编程题
1.输入2个整数,求两数的平方和并输出。
  #include <stdio.h>
void main()
{ intt  a ,b,s; 
printf("please input a,b:\n");
scanf("%d%d,&a,&b);
    s=a*a+b*b;
    printf("the result  is %d\n",s);   
} 
2. 输入一个圆半径(r),当r>=0时,计算并输出圆的面积和周长,否则,输出提示信息。
#include <stdio.h>
  #define PI 3.14
void main()
{ float  r ,s , l; 
printf("please input r:\n");
scanf("%f,&r);
    if (r>=0)                     
      {s=pi*r*r;
      l=2*i*r ;
      printf("the area is %f\n",s);   
printf("the circumference is %f\n",l);}
else 
printf("input error!\n");
} 
3、函数y=f(x)可表示为:
                  2x+1  (x<0)
            y=    0    (x=0)
                  2x-1  (x>0)
编程实现输入一个x值,输出y值。 
#include <stdio.h>
void main()
{ int x,y;
scanf(“%d”,&x);
if(x<0) y=2*x+1;
else if(x>0) y=2*x-1;
else y=0;
printf(“%d”,y);}
4、编写一个程序,从4个整数中出最小的数,并显示此数。
#include <stdio.h>
void main( )
{int a,b,c,d,t;
scanf (“%d,%d,%d,%d ”,&a,&b,&c,&d);
if (a>b)
  {t=a; a=b; b=t;}
if (a>c)
  {t=a; a=c; c=t;}
if (a>d)
  {t=a; a=d; d=t;}
printf (“min = %d \n”,a);
}
5.有一函数当x<0y=1,当x>0时,y=3,当x=0时y=5,编程,从键盘输入一个x值,输出y值。
#include <stdio.h>
void main()
{int x,y;
scanf("%d",&x);
if (x<0) y=1;
else if(x==0) y=5;
else y=3;
printf("x=%d,y=%d\n",x,y);}
6.从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中调用该
函数)   
#include <stdio.h>
float max(float x,float y);
void main()
{  float a,b,m;
scanf("%f,%f",&a,&b);
m=max(a,b);
printf("Max is %f\n",m);
}
float max(float x,float y)
{
float temp;
if (x<y)
{temp=x;
      x=y;
y=temp;
}
return(x);
}
7从键盘输入你和你朋友的年龄,编成判断谁的年龄最大,并打印最大者的年龄。
#include  <stdio.h>
void main()
{    int  yourAge, hisAge;
    printf("Please enter your age:");
    scanf("%d", &yourAge);      /*输入你的年龄yourAge*/
    printf("Please enter your friend's age:");
    scanf("%d", &hisAge);      /*输入你朋友的年龄hisAge*/
    if (yourAge >= hisAge)
     {
        printf("You are older! Your age is = %d\n", yourAge); 
     }
    if (hisAge > yourAge)
     {
        printf("Your friend is older! HisAge age is = %d\n", hisAge);
     }}
8、键盘输入2个加数,再输入答案,如果正确,显示“right”,否则显示“error
#include stdio.h
void main( )
{int a,b,c;
printf(“please input a and b\n);
scanf (%d,%d”,&a,&b);
printf(“please input the answer for a+b\n);
scanf (%d”,&c);
if (c==a+b)
    printf(“right\n);
else
    printf(“error\n);
}
9. 编一程序每个月根据每个月上网时间计算上网费用,计算方法如下:
               
要求当输入每月上网小时数,显示该月总的上网费用(6分)
#include <stdio.h>
void main()
{ int hour;
  float fee;
  printf(please input hour:\n);
scanf(%d,&hour);
if(hour<=10)
  fee=30;
else if(hour>=10&&hour<=50)
  fee=3*hour;
else fee=hour*2.5;
printf(The total fee is %f,fee);
}
10.神州行用户无月租费,话费每分钟0.6元,全球通用户月租费50元,话费每分钟0. 4元。输入一个月的通话时间,分别计算出两种方式的费用,判断哪一种合适。
  #include <stdio.h>
void main()
  { float a,x,y;
  printf(\n请输入您的话费:);
  scanf(%f,c语言编程小游戏,&a);
  x= 0.6*a;
  y=50+0.4*a;   
  printf (“神州行话费为: %f\n”,x);
printf (“全球通话费为: %f\n”,y);
if (x>=y)
      printf(建议使用全球通);
  else printf(建议使用神州行);
    }
11.个人所得税计算,应纳税款的计算公式如下:
收入
税率
收入<1000元部分
0%
2000>=收入>1000元的部分
5%
3000>=收入>2000元的部分
10%
6000>=收入>3000元的部分
15%
收入>6000元的部分
20%
输入某人的收入,计算出应纳税额及实际得到的报酬。(7分)
(如需连续计算多个人的纳税情况,直到输入负数为止,程序应如何改进?试写出程序)
#include stdio.h
void main()
{
  int grade;
  float income,tax,money;
  printf(“please input your income\n);
scanf (%f”,&income);
  if (income<0)
      printf(the input is error);
  else
{ grade=(int)income/1000;
  switch(grade)
      { case 0 : tax=0;break;
        case 1 : tax=(income-1000)*0.05;break;
        case 2 : tax=50+(income-2000)*0.1;break;
        case 3 :
case 4 :
case 5 : tax=150+(income-3000)*0.15;break;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。