题目是这样的:Useasingle-subscriptedarraytosolvethefollowingproblem.Readin20numbers,eachofwhichisbetween10and100,inclusive.Aseachnumberisread,printitonlyifitisnotaduplica...
题目是这样的:Use a single-subscripted array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Prepare for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.
我的问题是:怎样检验输入的数与以前输入过的数是否相同呢?用什么方法呢?
int main()
{
int nums[20];
int i;
printf("If the first number you type is not a right number, it will output the number 0.\n");
for(i=0;i<20;i++)
{ int counter=1;
printf("Please type in a number within the interval [10,100]:\n");
scanf("%d",&nums[i]);
rule=nums[0];
if(i==0)
printf("The number you have just typed is %d\n",nums[i]<100&&nums[i]>10?nums[i]:0);
else if(nums[i]<100&&nums[i]>10&&i!=0)
printf("The number you have just typed is %d\n",nums[i]);
else if (nums[i]>=100||nums[i]<=10)
printf(" The number you huve just typed is a wrong number.\n");
}
return 0;
}
展开