Loading... 分糖果问题 ``` #include <stdio.h> #include <math.h> int main() { int a[5] = {10, 14, 8, 22, 16}; int tmp[5]; int i; int count = 0; while (!(a[0] == a[1] && a[0] == a[2] && a[0] == a[3] && a[0] == a[4])) { for (i = 0; i < 5; i++) if (a[i] % 2 == 1) a[i] = a[i] + 1; for (i = 0; i < 5; i++) tmp[i] = a[i] / 2; for (i = 1; i < 5; i++) a[i] = tmp[i] + tmp[i - 1]; //后四个数字更新 a[0] = tmp[0] + tmp[4]; //第一个更新 count++; } printf("分%d次\n", count); for (i = 0; i < 5; i++) printf("%d\n", a[i]); return 0; } ``` 摘水果冠军问题 ```c #include <stdio.h> #include <string.h> int main() { int a[3][4] = {{2011, 57, 68, 40}, {2012, 60, 83, 72}, {2013, 40, 56, 69}}; int sum[3] = {0, 0, 0}; //保存每个人的水果重量 int i, j; int max, index; for (i = 0; i < 3; i++) { for (j = 1; j < 4; j++) sum[i] = sum[i] + a[i][j]; } max = sum[0]; index = 0; for (i = 1; i < 3; i++) { if (sum[i] > max) { max = sum[i]; index = i; } } printf("冠军是:%d", a[index][0]); return 0; } ``` 一共打了多少个单词 ``` #include <stdio.h> #include <string.h> int main() { char a[500]; gets(a); int count = 0; if (a[0] != ' ') count++; for (int i = 1; i < strlen(a); i++) { if (a[i] != ' ' && a[i - 1] == ' ') count++; } printf("一共的单词有:%d个", count); return 0; } ``` ``` #include<stdio.h> int main(){ int n; float a[6666],b[6666]; float sum,x; scanf("%d",&n); a[1]=1,b[1]=2; sum=2; for (int i=2;i<=n;i++) { b[i]=b[i-1]+a[i-1]; a[i]=b[i-1]; x=b[i]/a[i]; sum=sum+x; } printf("%.2f",sum); return 0; } ``` ```#include int main(){ int n,m,sum,ans; scanf("%d",&n); scanf("%d",&m); sum=n; ans=n; printf("%d ",n); for(int i=1;i<m;i++) { sum=sum*10+n; printf("+ %d ",sum); ans+=sum; } printf("= %d",ans); return 0; } ``` 最后修改:2023 年 10 月 12 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 1 如果觉得我的文章对你有用,请随意赞赏噢~