资源描述:
《C语言编程题目.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1、编程实现:从键盘输入3个变量的值,其中中a=5,b=6,c=7,然后将3个变量的值进行交换,使得a=6,b=7,c=5.#include"stdio.h"voidmain(){inta,b,c,m;printf("Entera,b,c:");scanf("%d,%d,%d",&a,&b&c);m=a;a=b;b=c;c=m;printf("a=%d,b=%d,c=%d",a,b,c);}2、编程实现:输入任意一个3位数,将其各位数字反序输出(例如:输入123,输出321)。#include"stdio.h"voidmain(){inta,b,c,x,y;printf("输入一个
2、3位数:");scanf("%d",&x);a=x%10;b=x/100;c=x%100/10;y=a*100+c*10+b;printf("%d",y);}1、编程实现:输入三角形的边长,求三角形面积(面积=sqrt(s(s-a)(s-b)(s-c)),s=(a+b+c)/2.#include#includevoidmain(){inta,b,c;floatx,y;scanf("%d,%d,%d",&a,&b,&c);x=(a+b+c)/2;y=sqrt(s*(s-a)*(s-b)*(s-c));printf("%.3f",y);}2、编
3、程实现:从键盘上输入一个年月日,要求出该天是该年的第几天(注意判断该年是否是闰年)。#includevoidmain(){inta,b,c;printf("输入一个年月日:");scanf("%d%d%d",&a,&b,&c);if(a%4==0
4、
5、a%100==0)switch(b){case1:printf("%d",c);break;case2:printf("%d",31+c);break;case3:printf("%d",60+c);break;case4:printf("%d",91+c);break;case5:printf("%d
6、",121+c);break;case6:printf("%d",152+c);break;case7:printf("%d",182+c);break;case8:printf("%d",213+c);break;case9:printf("%d",244+c);break;case10:printf("%d",274+c);break;case11:printf("%d",305+c);break;case12:printf("%d",335+c);break;}elseswitch(b){case1:printf("%d",c);break;cas
7、e2:printf("%d",31+c);break;case3:printf("%d",59+c);break;case4:printf("%d",90+c);break;case5:printf("%d",120c);break;case6:printf("%d",151+c);break;case7:printf("%d",181+c);break;case8:printf("%d",212+c);break;case9:printf("%d",243+c);break;case10:printf("%d",273+c);break;case1
8、1:printf("%d",304+c);break;case12:printf("%d",334+c);break;}}1、求∑n!(1!+2!+3!+...+25!)。(n从1到25)#includevoidmain(){floatsum=1,term=0;for(i=1;i<=25;i++){sum=sum*i;term=term+sum;}printf("%d,%f",i,term);}1、编写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的信息。#includeintf(int,a);voidmain(){inta,y
9、;scanf("%d",&a);if(a<2)printf("输入有误:");elseif(a==2)printf("a为素数:");else{y=f(a);if(y==1)printf("a为素数:");elseprintf("a不为素数:");}}1、键盘输入10个整数,用冒泡排序法按从小到大的顺序输出。#includevoidmain(){inti,m,a[10];for(i=0;i<10;i++)scanf("%d",