#include<stdio.h> int main()//求152个十百位,b个位,c十位,d百位 { int a=152; int b; int c; int d; b=a/100; c=(a/10)%10; d=a%10; printf("%d %d %d",b,c,d); }
#include<stdio.h> int main()//三角形 { printf("* "); printf("* * "); printf("* * * "); printf("* * * * "); printf("* * * * * "); printf("* * * * * * "); printf("* * * * * * * "); printf("* * * * * * * * "); printf("* * * * * * * * * "); printf("* * * * * * * * * * "); }
#include<stdio.h> #include<math.h> int main()//分段函数 { double x; double y; scanf("%lf",&x); if(x>=0) y=sqrt(x); else y=pow(x+1,2)+2*x+1/x; printf("f(x)=%f",y); return 0; }
#include<stdio.h> int main()// 矩形 { printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); printf("* * * * * * * * * * "); }
#include<stdio.h> int main()//倒三角 { printf("* * * * * * * * * * "); printf(" * * * * * * * * * "); printf(" * * * * * * * * "); printf(" * * * * * * * "); printf(" * * * * * * "); printf(" * * * * * "); printf(" * * * * "); printf(" * * * "); printf(" * * "); printf(" * "); }
#include<stdio.h> int main()//五级制(A-E) { char score; scanf("%c",&score); switch(score) { case 'A': printf("优秀"); break; case 'B': printf("良好"); break; case 'C': printf("中等"); break; case 'D': printf("及格"); break; case 'E': printf("不及格"); break; } return 0; }
#include<stdio.h> #include<math.h> int main()//温度 { int c; int f; printf("请输入华氏温度: "); scanf("c=%d",&f) ; c=5*(f-32)/9; return 0; }
#include<stdio.h> int main()//自由落体 { int height; int t=3; int g=10; height=0.5*g*t*t; printf("%f ",height); return 0; }