If user give a number out of range program asks again for a valid number.
This program is here so reader can understand better how this little program is written in MIPS code. The same in MIPS code is here.
#include <stdio.h>
int main() {
int x,i;
do{
printf("Please give an integer from 1 to 20 : ");
scanf("%d",&x);
}
while( x>20 || x<1 );
for (i=1;i<=x;i++) {
printf("%d\n",i);
}
exit(0);
}
No comments:
Post a Comment