Professional Documents
Culture Documents
If Else
If Else
Zubair Hossain
Roll: 1904038
Department: ETE
Problem 1:
#include<stdio.h>
int main()
{
int n ;
printf("Input a number : ");
scanf("%d",&n);
if(n<0) printf(" The number is invalid");
else if(n%2!=0) printf(" %d is an odd number",n);
else printf(" %d is an even number",n);
}
Output of problem 1:
Page 1 of 6
Problem 2:
#include<stdio.h>
int main()
{
int n ;
printf("Input a number : ");
scanf("%d",&n);
if(n%2!=0)
{
if(n>0) printf(" %d is a positive number and it is an odd number\n",n);
Page 2 of 6
Output of problem 2:
Page 3 of 6
Page 4 of 6
Problem 3:
#include<stdio.h>
int main()
{
int n ;
printf("Input a number : ");
scanf("%d",&n);
if(n>=0)
{
printf(" %d is a positive number\n",n);
if(n>=10)
printf(" %d is greater than or equal 10\n",n);
else
printf(" %d is less than 10 \n",n);
}
else
{
printf(" %d is a negative number\n",n);
if(n>=-10)
printf(" %d is greater than or equal -10\n",n);
else
printf(" %d is less than 10 \n",n);
}
Output of problem 3:
Page 5 of 6
Page 6 of 6