Tuesday, February 16, 2016

C program to validate user input.

//Check marks is in the range of 0 to 100.

#include<stdio.h>
void main()
{
int marks;

printf("Enter marks:");
scanf("%d",&marks);

if(marks > 100 || marks < 0 )
printf("Invalid marks.\nEnter marks in a range of 0-100.");
else
printf("Your marks are %d", marks);
}
/*Output1
Enter marks:80
Your marks are 80
*/

/*Output2
Enter marks:120
Invalid marks.
Enter marks in a range of 0-100.
*/


No comments:

Post a Comment