Saturday, April 11, 2009

Example of compound statement & nested if

/*Prompts for and accepts input of an integer.Integer is tested to see that it meets the stated criteria.If it doesn't an error message is issued.If all criteria are met,execution terminates silently*/

*Solution Code:-
===========

#include <stdio.h>
int mod(int i);
int main(void)
{
int i;
printf("Enter an Even number less than 20 : ");
scanf("%d",&i);

if ( i < 20)
{
if ( mod(i))
printf("Oops you entered Odd number %d",i);
else if ( i <= 0 )
printf("Oops you entered number less than or equal to 0 %d",i);
}
else
printf("You entered a number greater than 20");



return 0;
}

int mod(int i)
{
return ( i % 2 );
}

No comments: