Q:

Write a C program that reads an integer and check the specified range where it belongs. Print an error message if the number is negative and greater than 80

0

Write a C program that reads an integer and check the specified range where it belongs. Print an error message if the number is negative and greater than 80.

Test Data :
Input an integer: 15
Expected Output:
Range [0, 20]

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main() {
	int x;
	printf("\nInput an integer: "); 
	scanf("%d", &x);
	if(x >=0 && x <= 20) 
	{
		printf("Range [0, 20]\n");
	} 
	else if(x >=21 && x <= 40) 
	{
		printf("Range (25,50]\n");
	} 
	else if(x >=41 && x <= 60) 
	{
		printf("Range (50,75]\n");
	} 
	else if(x >61 && x <= 80) {
		printf("Range (61,80]\n");
	} 
	else 
	{
	printf("Outside the range\n");
	}	
	return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Basic Declarations and Expressions exercises

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program that read 5 numbers and sum of a... >>
<< Write a C program to print the roots of Bhaskaraâ€...