Basically i have this task to get 2 inputs stored into num1 and num2 of int type. The program will then list all the possible numbers from 0 to num1, which are divisable by num2.
So if my input is 10 and 2
my output should be 2 4 6 8.
the problem now is that if i type in negative value or a character i won't get a correct output.
so i came up with this validation :
which is not efficient at all. cause instead of re-prompting for another input of num1, it just exits. and if it is NULL a different message should be printed. like "Please enter in a number".
Is there a solution to this? assuming that you only know arrays, pointers, and conditions, and the only lib you know of is stdio.
So if my input is 10 and 2
my output should be 2 4 6 8.
the problem now is that if i type in negative value or a character i won't get a correct output.
so i came up with this validation :
Code:
if(num1 < 0 || num1==NULL){
printf("enter a number greater than 0");
return 0;
}
Is there a solution to this? assuming that you only know arrays, pointers, and conditions, and the only lib you know of is stdio.
Comment