本文共 523 字,大约阅读时间需要 1 分钟。
返回:
【项目1-有几个】
请编程序,输入若干个正数(不超过100个,以0结束),保存在数组中。再输入一个正数n,输出n在前面出现过多少次?[参考解答]
思路:将输入的数保存到数组中,并且需要记录下一共有多少个数。由于不能保证这些数的顺序,n出现的次数需要通过顺序查找的方法进行,且需要考察所有的数字。
#include#define SIZE 100int main( ){ int d[SIZE]; int x, i=0, len; //len代表数组中有效的数字个数 int n, count=0; //count用于记录n出现的次数 printf("Input some number(the last is -1): "); scanf("%d" , &x); while(x!=-1) { d[i++]=x; scanf("%d" , &x); } len =i; printf("Input a key you want to search: "); scanf("%d" , &n); for(i=0; i
转载地址:http://thdzm.baihongyu.com/