C language program || If, If Else, Nested If :
![]() |
| C language program |If, If Else, Nested If |
⇒Creator value in 2 number-
#include<stdio.h>
#include<conio.h>
void main()
{
int first,second;
clrscr();
printf("Enter the first number=\n");
scanf("%d",&first);
printf("Enter the second number=\n");
scanf("%d",&second);
if(first>second)
{
printf("First no is greater");
}
if(first<second)
{
printf("second number is greater");
}
if(First=second)
{
printf("Both are equal");
}
OUTPUT :
Enter the first number=
45
Enter the second number=
25
First, no is greater
⇒Greater value in 3 number using if statement-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the first number=\n");
scanf("%d",&a);
printf("Enter the second number=\n");
scanf("%d",&b);
printf("Enter the third number=\n");
scanf("%d",&c);
if(a>b&&a>c)
{
printf("%d is greater",a);
}
if(b>a&&b>c)
{
printf("%d is greater",b);
}
if(c>a&&c>b)
{
printf("%d is greater",c);
}
getch();
}
OUTPUT :
Enter the first number=
8
Enter the second number=
12
Enter the third number=
6
12 is greater
Check given number is positive or negative or zero-
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter any number=\n");
scanf("%d",&no);
if(no>0)
{
printf("no is positive");
}
if(no<0)
{
printf("no is negative");
}
if(no==0)
{
printf("no is zero");
}
getch();
}
OUTPUT :
Enter any number=
8
no is positive
Show result According to percent using if statement-
#include<stdio.h>
#include<conio.h>
void main()
{
float p;
clrscr();
printf("Enter your percent=\n");
scanf("%f",&p);
if(p<=100 && p>=60)
{
printf("First division");
}
if(p<60 && p>=45)
{
printf("second division");
}
if(p<45 && p>=33)
{
printf("third division");
}
if(p<33)
{
printf("Fail");
}
getch();
}
OUTPUT :
Enter your percent=
50
Second
Even Odd number-
#include<stdio.h>
#include<conio.h>
void main()
{
int no;
clrscr();
printf("Enter any number=\n");
scanf("%d",&no);
if(no%2==0)
{
printf("Even");
}
else
{
printf("odd");
}
getch();
}
OUTPUT :
Enter any number=
21
Odd
Check character is vowel or Consonant-
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter any alphabet=\n");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
printf("Vowel");
}
else
{
printf("Consonent");
}
getch();
}
OUTPUT:
Enter alphabet
m
Consonent
Check alphabet in upper case or lower case-
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf(Enter any alphabet=\n");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
{
printf("Uppercase");
}
else
{
printf("Lowercase");
}
getch();
}
OUTPUT :
Enter any alphabet
D
Uppercase
Login Program:
#include<stdio.h>
#include,conio.h>
void main()
{
char u[200]="sseffort@gmail.com" ,p[200]="12345";
char u1[200],p[200];
printf("Enter user name\n");
scanf("%s",&u1);
printf("Enter password\n");
scanf("%s",&p1);
if(strcmp(u,u1)==0&&strcmp(p,p1)==0)
{
printf("Login sucessfull");
}
else
printf("Wrong user name or password");
}
getch();
}
OUTPUT:
Enter user name
sseffort@gmail.com
Enter password
12345
Login successful
Input three angles of triangle and check tringle is valid or not-
#include<stdio.h>
#include<conio.h>
void main()
{
float s1,s2,s3;
printf("Enter first angel=\n");
scanf("%f",&s1);
printf("Enter second angel=\n");
scanf("%f",&s2);
printf("Enter third angel=\n");
scanf("%f",&s3);
if((s1+s2+s3)==180)
{
printf("Tringle is valid");
}
else
{
printf("Tringle is not valid");
}
getch();
}
OUTPUT :
Enter first angel=
45
Enter second angel=
85
Enter third angel=
50
Tringle is valid
Calculate profit and Loss-
#include<stdio.h>
#include<conio.h>
void main()
{
float sp,cp,profit,loss;
printf("Enter cost price\n");
scanf("%f",&cp);
printf("Enter selling price\n");
scanf("%f",&sp);
if(sp>cp)
{
profit=sp-cp;
printf("Profit is %f rupee",profit);
}
else
{
loss=cp-sp;
printf("Loss is %f rupee",loss);
}
getch();
}
OUTPUT :
Enter cost price=
50
Enter celling price=
20
Loss is 30 rupee
Show result according to percent using if-else statement-
#include<stdio.h>
#include<conio.h>
void main()
{
float p;
clrscr();
printf("Enter your percent=\n");
scanf("%f",&p);
if(p>=60)
{
printf("First division");
}
else if(p>=45)
{
printf("Second division");
}
else if(p>=33)
{
printf("Third division");
}
else
{
printf("Fail");
}
getch();
}
OUTPUT :
Enter your percent=
70
First division
Check given character is alphabet or digit or special symbol-
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter any character\n");
scanf("%c",&ch);
if(ch>=65 && ch <=97 || ch>=97 &&ch<=122)
{
printf("It is alphabate");
}
else if(ch>=48 && ch<=57)
{
printf("it is digit");
}
else
{
printf("It is a special symbol");
}
getch();
}
OUTPUT :
Enter any character
@
It is a special symbol

0 Comments
Please do not enter any spam link in the comment box