15-01
-
- 题目问题描述:
- 思路分析:
- 结果截图:
- 实现代码:
题目问题描述:
思路分析:
问题:
- 求和;
结果截图:
实现代码:
#include<stdio.h>
int main(){int a[10]={0};int sum = 0;int count = 0;printf("输入10个整数:"); //1 2 3 -4 5 -6 7 8 -9 10for(int i = 0;i < 10;i++){scanf("%d",&a[i]);}printf("\n其中正数有:");for(int j = 0;j < 10;j++){if(a[j] > 0){printf("%d,",a[j]);sum += a[j];count++;}}printf("\n%d个正数和:", count);printf("%d\n",sum);
}
实现代码答:
#include<stdio.h>
int main(){int i, a[10], b[10];int j = 0, sum = 0;printf("please input ten number:\n");for(i=0; i<10; i++){scanf("%d", &a[i]);if(a[i] > 0){b[j] = a[i];sum = sum + b[j];j++;}}printf("这10个数中的正数是:");for(i=0; i<j; i++){printf("%d,", b[i]);}printf("\n这%d个正数的和是:%d\n", j, sum);return 0;
}