Write a program to check weather a number is positive or not positive using IF
Q1 Write a program to check weather a number is positive or not positive using if
IF ----If statement is one of the simplest decision making control statement.
Syntax
If (expression)
{
Frist Statement
;
…… ………… ……… …………..
…… ………… ………… ………
Last statement;
}
How to work if statement
The if statement evaluates the take a look at expression
within the parenthesis ().
If test condition is
evaluated to true, statements within the body of if are executed.
If test condition is
evaluated to false, statements within the body of if don't executed
If condition is true
Int check =10;
If (check < 33)
{
// executed code
}
// executed code after if
If condition is false
Int check =10;
If (check >33)
{
// executed code
}
// executed code after if
PROGRAM
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int a;
printf("ENTER
A NUMBER");
scanf("%d",&a);
if (a>0)
{
printf("positive number");
}
if(a<=0)
{
printf("non positive number");
}
return
(EXIT_SUCCESS);
}
OUTPUT
Q 2 WRITE A C PROGRAM TO CHECK WEATHER RESULT
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int a;
printf("ENTER
A RESULT");
scanf("%d",&a);
if (a>=33)
{
printf("PASS");
}
if(a<33)
{
printf("BUTTER LUCK NEXT TIME");
}
return (EXIT_SUCCESS);
}
OUTPUT
Q3 Write a c program to check a voting AGE condition
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int a;
printf("ENTER
A AGE");
scanf("%d",&a);
if (a>=18)
{
printf("YOU CAN VOTE");
}
if(a<18)
{
printf("YOU CAN'T VOTE");
}
return
(EXIT_SUCCESS);
}
OUTPUT
Comments
Post a Comment