Simple IF Statement
|
Here is an example for simple if statement.
if statement evaluates the condition inside the paranthesis and if it is true, then it executes one line followed by if statement or the sequence of steps bound of { }.
Source Code
#include <stdio.h>
void main()
{
int x;
printf("Enter a Number: ");
scanf("%d", &x);
if(x < 0)
printf("%d is a negative number\n", x);
}
Output
Enter a Number: -100
-100 is a negative number
//write a program to print the largest number
উত্তরমুছুন//from any four numbers.
#include
main()
{
int a,b,c,d;
printf("The value of a :");
scanf("%d",&a);
printf("\nThe value of b :");
scanf("%d",&b);
printf("\nThe value of c :");
scanf("%d",&c);
printf("\nThe value of d :");
scanf("%d",&d);
if((a>b)&&(a>b)&&(a>c))
printf("\nThe largest number: %d",a);
else
if((b>c)&&(b>d))
printf("\nThe largest number: %d",b);
else
if(c>d)
printf("\nThe largest number: %d",c);
else
printf("\nThe largest number: %d\n",d);
}
///simple if statement///
উত্তরমুছুন#include
main()
{
int n;
printf("Enter a number");
scanf("%d",&n);
if(n<1)
printf("%d is a negative number\n:",n)
}
///simple if statement///
উত্তরমুছুন#include
main()
{
int n;
printf("Enter a number:");
scanf("%d",&n);
if(n<1)
printf("%d is a positive number\n",n);
return 0;
}
### simple if statement ####
উত্তরমুছুন#include
main()
{
int r;
printf("enter a number");
scanf("%d,& r);
if(r>1)
printf("%d is a positive number\n",r);
}
#include
উত্তরমুছুনmain()
{
int y;
printf("enter a number");
scanf("%d",&y);
if(y<0)
printf("% d is a positive number\n"y);
}