Tuesday, August 30, 2022

C Program to Demonstrate else-if statement

if-else-if in C

In else – if a programmer can make decision among multiple conditions. In C "if statements" are executed from the top down approach. As soon as one of the if is true, the statement associated with if is executed, and the rest of the C else – if is bypassed. If none of the conditions are true, then the final else statement will be executed.

Syntax: 


if (condition)

    statement;
else if (condition)
    statement;
else if (condition)
    statement;
else if (condition)
    statement;
.
.
else

    statement;
Youtube Video


Flow Chart



Sorce Code

 //WAP to enter any three number

//and find the largest

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n1, n2, n3;

printf("Enter any three numbers \n");

scanf("%d%d%d",&n1,&n2,&n3);

if(n1>n2 && n1>n3)

printf("%d is larger than %d and %d",n1,n2,n3);

else if(n2>n1&&n2>n3)

printf("%d is larger than %d and %d",n2,n1,n3);

else

printf("%d is larger than %d and %d",n3,n1,n2);

printf("\nEnd of program");

getch();

}


Tuesday, August 9, 2022

C Program to understand the concept of "if-else" statement in C by Satyam Srivastava

C Program to understand the concept of "if-else" statement in C by Satyam Srivastava

If-else Statement

The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the true condition, and the other is for the false. Here, we must notice that if and else block cannot be executed in same time. The syntax of the if-else statement is given below.

if(condition)

{  

//code to be executed if condition is true  

}

else

{  

//code to be executed if condition is false  

}  

Youtube Video

 Flow Chart

Sorce Code

//WAP to understand the concept of
//if-else statement
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("Enter any number\n");
scanf("%d",&n);
if(n % 2 == 0)
{
printf("Even number");
}
else
{
printf("Odd number");
}
getch();
}

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();

}

 

C Program to show the use of Mathematical Expressions


 

Program to find the sum of two number


 

Installation of Turbo C on windows PC