Syntax:-
if(condition)
{
----------
----------
}
( or )
if(condition)
Statement;
In this statement we can check only one condition.It executes only true statement.
First it checks the condition.
If the condition is true it executes true statement and then goes to next statement.
If the condition is false it is directly goes to next statement.
Flow chart:-
#include<stdio.h>
#include<conio.h> void main() { int n; clrscr(); printf("enter a value:"); scanf("%d",&n); if(n>10) printf(“AMBATI DURGA PRASAD"); getch(); } |
Output:-
enter a value: 14 AMBATI DURGA PRASAD |
* Write a program to input number is lowest no of 20.
#include<stdio.h>
#include<conio.h> void main() { int a=10; clrscr(); If(a<=20) printf(“a is less than 20”); getch(); } |
Output:-
a is less than 20 |
#include<stdio.h>
#include<conio.h> void main() { int a; clrscr(); printf(“enter the a value:”); scanf(“%d”,&a); If(a<=20) printf(“a is less than 20”); getch(); } |
Output:-
enter the a value:19 a is less than 20 |
#include<stdio.h>
#include<conio.h> void main() { int age; clrscr(); printf(“enter your age:”); scanf(“%d”,&age); If(age>18) printf(“you are eligible for vote”); printf(“\n Thank you”); getch(); } |
Output:-
enter your age: 23 you are eligible for vote Thank you |
#include<stdio.h>
#include<conio.h> void main() { int age; clrscr(); printf(“enter your age:”); scanf(“%d”,&age); If(age>=13&&age<=19) printf(“you are teenager”); printf(“\n Thank you”); getch(); } |
Output:-
enter your age:15 you are teenager Thank you |
* Write a
program input two numbers & print the largest value.
#include<stdio.h>
#include<conio.h> void main() { int a,b,big; clrscr(); printf(“enter any two numbers:”); scanf(“%d%d”,&a,&b); big=a; If(big<b) big=b; printf(“big value=%d”,big); getch(); } |
Output:-
enter any two numbers: 5 9 big value=9 |
* Write a program input three numbers & print the largest value.
#include<stdio.h> #include<conio.h> void main() { int a,b,c,big; clrscr(); printf(“enter any three numbers:”); scanf(“%d%d%d”,&a,&b,&c); big=a; If(big<b) big=b; if(big<c) big=c; printf(“big value=%d”,big); getch(); } |
Output:-
enter any three numbers: 7 3 5 big value=7 |
___________________________________________________________________________________
___________________________________________________________________________________
_____________________________________________
Post a Comment