Tuesday 26 October 2010

if else statement


The if...else statement is used if the programmer wants to execute some statement/s when the test expression is true and execute some other statement/s if the test expression is false.
Syntax of if...else
if (test expression) {
     statements to be executed if test expression is true;
}
else {
     statements to be executed if test expression is false;
}
Flowchart of if...else statement


//find out the avg of the student using if else
#include<stdio.h>
#include<conio.h>
void main()
{
 int grade;
 char student[25],section[25];
 clrscr();
 printf(“Enter the name of a student: “);
 scanf(“%s”, &student);
 printf(“Enter the section of a student: “);
 scanf(“%s”, &section);
 printf(“Enter the grade of a student: “);
 scanf(“%d”, &grade);

 if(grade>75)
 {
   printf(“PASSED”);
 }
 else
 {
   print(“FAILED”);
 }
 getch();
}



Conditional statements

example programs on if..else


No comments:

Post a Comment