#1:星号金字塔函数
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5 - i; j++) { printf(" "); } for (int j = 0; j < 2 * i + 1; j++) { printf("*"); } printf("\n"); } system("pause"); return 0; }
#2星号的金字塔和倒金字塔code
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5 - i; j++) { printf(" "); } for (int j = 0; j < 2 * i + 1; j++) { printf("*"); } printf("\n"); } for (int i = 5; i < 9; i++) { for (int j = 0; j < i-3; j++) { printf(" "); } for (int j = 0; j < 17-2 * i ; j++) { printf("*"); } printf("\n"); } system("pause"); return 0; }
#3:星号出现位移的用法游戏
#include<stdio.h> #include<stdlib.h> int main() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 5 - i; j++) { printf(" "); } for(int j=0;j<6;j++) { printf("*"); } printf("\n"); } system("pause"); return 0; }
#4:找最值get
#include<stdio.h> #include<stdlib.h> int main() { int a, b, c, d; printf("请输入数值:"); scanf("%d", &a); printf("请输入数值:"); scanf("%d", &b); printf("请输入数值:"); scanf("%d", &c); printf("请输入数值:"); scanf("%d", &d); if (a > b && a > c && a > d) printf("Largest:%d", a); else if (b > a && b > c && b > d) printf("Largest:%d", b); else if (c > b && c > a && c > d) printf("Largest:%d", c); else printf("Largest:%d", d); if (a < b && a < b && a < d) printf("Smallest:%d", a); else if (b < a && b < c && b < d) printf("Smallest:%d", b); else if (c < a && c < b && c < d) printf("Smallest:%d", c); else printf("Smallest:%d", d); system("pause"); return 0; }
#5:买卖货物io
#include<stdio.h> #include<stdlib.h> int main() { float x, y,z; while (1) { printf("请输入价格:"); scanf("%f", &x); printf("请输入顾客付款:"); scanf("%f", &y); z = y - x; getchar(); while (z < 0) { printf("交易失败\n"); printf("请输入价格:"); scanf("%f", &x); printf("请输入顾客付款:"); scanf("%f", &y); } if (z == 0) { printf("交易成功!"); } else if (z > 0) printf("找给顾客%f元,交易成功!", z); break; } system("pause"); return 0; }
#6:写函数class
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { float x, a, b, c, d,y; printf("请输入一个x值:"); scanf("%f", &x); a = sin(x); b =log(x + 1); c = exp(2);//exp函数为e的表达函数// d = fabs(cos(x));//fabs函数为绝对值函数// y = (a + b )/(c + d); if (x > -1) printf("得出的值为%f", y); else printf("得出的值不存在"); system("pause"); return 0; }
#7:写一个数的以前偶数平方float
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int N,y,j; printf("请输入一个数值N:"); scanf("%d", &N); y=sqrt(N); for (int i = 1; i <= y/2; i++) { j = 2 * i*i*2; printf("%d\n",j); } system("pause"); return 0; }
#8:公约数最大im
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int x1,x2, y1,y2, z,o,p; char sel; while (1) { printf("请输入一个实数:"); scanf("%d", &x1); printf("请输入另外一个实数:"); scanf("%d", &y1); x2 = x1; y2 = y1; if (x1 < y1) { o = x1; x1 = y1; y1 = 0; } z = x1 % y1; while (z != 0) { x1 = y1; y1 = z; z = x1 % y1; } p = x2 * y2 / y1; printf("最小公倍数为%d\n", p); printf("最大公约数为%d", y1); } system("pause"); return 0; }
#9:猜数游戏di
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int x,y,z,count=0; srand((unsigned)time(NULL)); y = rand(); z = y % 10; while (count<=5) { printf("请输入一个0到9的数:"); scanf("%d", &x); if (x < z) { printf("你输入的值太小,请重输:"); scanf("%d",&x); } if (x > z) { printf("你输入的值过大,请重输:"); scanf("%d", &x); } if (x == z) { printf("恭喜你输入正确"); break; } count++; if (count == 5) { printf("你已猜完5次,欢迎下次再玩:"); break; } break; } system("pause"); return 0; }
#10:对比数字while
#include<stdio.h> #include<stdlib.h> int main() { float x,i=0; printf("Enter a number:"); scanf("%f", &x); while (x > 0) { printf("Enter a number:"); scanf("%f", &x); i = (x > i) ? x : i; } printf("the largest number is %f", i); system("pause"); return 0; }