C语言课程训练系统题-重庆邮电大学

C语言课程训练系统题-基础习题

  • 1.爱因斯坦
  • 2.输出两数最大值
  • 3.输出两数商
  • 4.12a4.2
  • 5判断3个数是否相等
  • 6输入一个数,逆序输出这个数
  • 7求三角形面积
  • 8四则运算
  • 9求2/1,3/2,5/3,8/5,13/8,21/13,.....前20项之和
  • 10小写转大写
  • 11大写转小写
  • 12输入两数求商
  • 13计算心跳次数
  • 14输出指定文字
  • 15温度转换
  • 16体重指数
  • 17大象喝水
  • 18输出大写字母,所占内存大小
  • 19改错12a4.
  • 20输出N个阶乘

1.爱因斯坦

#include <stdio.h>main(){int  x,find=1;x=0;    do{        x  ;       if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0)find=0;     }while (find);      printf("x=%d\n",x);}

2.输出两数最大值

#include<stdio.h>main(){int a,b,max;printf("Input a, b:");scanf("%d,%d",&a,&b);if (a>b) max = a;if (a<=b) max = b;printf("max = %d\n",max);}

3.输出两数商

#include <stdio.h>main(){    int a,b;double c;printf("Input two integers:");    scanf("%d%d",&a,&b);    c = a/b;    printf("The quotient of a and b is :%.f",c);}

4.12a4.2

#include <stdio.h>main(){    int i;    char ch;    float f;    printf("Please input:\n");    scanf("%d%c%f",&i,&ch,&f);    printf("The input integer is : %-3d\nThe input character is : %c\n",i,ch);    printf("The input float is : %f",f);}

5判断3个数是否相等

#include <stdio.h> main(){    int a,b,c;scanf("%d%d%d",&a,&b,&c);    if (a==b&&a==c)        printf("The three number is equal!!!");    else        printf("The three number isn't equal!!!");}

6输入一个数,逆序输出这个数

#include<stdio.h>main(){int x,a,b,c,d,y;printf("Input x:");scanf("%d",&x);if(x<0)d=(-x);elsed=x;a=d/100;b=(d-a*100)/10;c=d;y=a b*10 c*100;printf("y = %d\n",y);}

7求三角形面积

#include<stdio.h>#include<math.h>main(){float a,b,c,s,area;printf("Enter 3 floats");scanf("%f,%f,%f",&a,&b,&c);s=(a b c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c));printf("area=%.2f\n",area);}

8四则运算

#include<stdio.h>#include<math.h>main(){float a,b;char op;printf("Please enter the expression:\n");scanf("%f %c%f",&a,&op,&b);switch(op){case' ':printf("%f   %f = %f \n",a,b,a b);break;case'-':printf("%f - %f = %f \n",a,b,a-b);break;case'*':printf("%f * %f = %f \n",a,b,a*b);break;case'^':printf("%f ^ %f = %f \n",a,b,pow(a,b));break;case'/':if(b==0)printf("Division by zero!\n");elseprintf("%f / %f = %f \n",a,b,a/b);break;default:printf("Invalid operator! \n");}}

9求2/1,3/2,5/3,8/5,13/8,21/13,…前20项之和

#include <stdio.h>main(){    double i, s1 = 2, s2 = 1;    float x, sum = 0;for (i = 1; i <= 20; i  )    {        sum  =( s1 / s2);        x = s1;        s1  = s2;        s2 = x;    }    printf("sum = %f\n", sum);}

10小写转大写

#include<stdio.h>main(){char c1,c2;c1=getchar();c2=c1-32;printf("%c,%d\n",c2,c2);}

11大写转小写

#include<stdio.h>main(){char c1,c2;printf("Press a key and then press Enter:");c1=getchar();c2=c1 32;printf("%c\n",c2);}

12输入两数求商

#include <stdio.h>main(){    int a,b,c;printf("Enter two numbers");scanf("%d%d",&a,&b);if(b==0)printf("cannot divide by zero.\n");elsec=a/b;printf("%d",c);}

13计算心跳次数

#include<stdio.h>#include<math.h>main(){int n,c;printf("Please input your age: ");scanf("%d",&n);c=n*365*24*60*75;printf("The heart beats in your life: %d",c);}

14输出指定文字

#include<stdio.h>main(){printf("*****************************\n");printf("* C programming            *\n");printf("* Hello world!          *\n");printf("*****************************\n");}

15温度转换

#include<stdio.h>#include<math.h>main(){double t,T;printf("Please input fahr: ");scanf("%lf",&t);T=5.0*(t-32.0)/9.0;printf("The cels is: %.2f",T);}#include<stdio.h>#include<math.h>main(){double t,T;printf("Please input cels: ");scanf("%lf",&t);T=t*9.0/5.0 32.0;printf("The fahr is: %.2f",T);}

16体重指数

#include<stdio.h>#include<math.h>main(){int w,h,weight;double height,t;printf("Input weight, height:\n");scanf("%d,%d",&w,&h);weight=w*2;height=h/100.00;t=w/(height*height);printf("weight=%d\n",weight);printf("height=%.2f\n",height);printf("t=%.2f\n",t);}

17大象喝水

#include<stdio.h>#include<math.h>main(){int h,r,n;float PAI=3.14159;scanf("%d,%d",&h,&r);n=20000/(h*r*r*PAI);printf("please input the height and the radius:\n%d",n 1);}

18输出大写字母,所占内存大小

#include<stdio.h>main(){char c1,c2;printf("please input a lowercase:\n");c1=getchar();c2=c1-32;printf("%c %d %d\n",c2,c2,sizeof(c2));}

19改错12a4.

#include <stdio.h>main(){    int i;    char ch;    float f;    printf("Please input:\n");    scanf("%d%c%f",&i,&ch,&f);    printf("The input integer is : %d \nThe input character is : %c\n", i, ch);    printf("The input float is : %f", f);}

20输出N个阶乘

#include<stdio.h>#include<math.h>main(){int i,n;long p=1;printf("Please enter n:");scanf("%d",&n);for(i=1;i<=n;i  ){p=p*i;printf("%d! = %ld\n",i,p);}}

注:其余39道基础题在我资源文档中。来源:https://www.icode9.com/content-4-799351.html

(0)

相关推荐