Tuesday, August 9, 2022

C Program to to understandthe concept of “if” statement

C - if statement

An if statement consists of a Boolean expression followed by one or more statements.

Syntax :

The syntax of an if statement in C programming language is −

if (condition)

{

statement(s) will execute only if the boolean expression is true

}

If the Boolean expression evaluates to true, then the block of code inside the 'if' statement will be executed. If the Boolean expression evaluates to false, then the first set of code after the end of the 'if' statement (after the closing curly brace) will be executed.





/*Program to demonstrate if statement in C WAP to input total mark and mark obtained by student and determine his result according to given condition if percentage less than 50% then fail otherwise pass.*/

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int mo, tm, per;

printf("Enter total Marks\n");

scanf("%d",&tm);

printf("Enter Marks obtained by student\n");

scanf("%d",&mo);

per=mo*100/tm;

printf("Percentage obtained by student = %f",per);

if(per<50)

            {

            printf("\nFail");

            }

if(per>=50)

            {

            printf("\nPass");

            }

getch();

}

 

No comments:

Post a Comment