C create Array and check for Input Error

Simple question. I am trying to build a simple script that will ask you for a number. That integer will be the amount of numbers you will enter in total. Then your program finds the biggest number and the smallest. And I have build that. Easy. int CHECK=100; int a[50],size,i,max,min; printf("\nEnter the size of the array: "); scanf("%d",&size); printf("\nEnter %d numbers: ", size); for(i=0;ia[i]) min=a[i]; } printf("Smallest element: %d",small); printf("\n"); return 0; } My question is, how can I tell to check for conditions. For instance, the user can input only positive numbers and smaller than 100. So if you enter -4 or 201 an Error has to be displayed telling you to try again. Any ideas as of how we can do that in a simple way. Or even point me to the right direction. I appreciate it. Thank you.
Why do you feel that you must store the numbers? Consider looking for the smallest/largest as each number is entered, then you don't have to have a static limit (50) on how many numbers can be accepted. Designing programs to not have static limits is generally preferable.

以上就是C create Array and check for Input Error的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准