Professional Documents
Culture Documents
Flocharts Selection For C
Flocharts Selection For C
STRUCTURES
IN C USING FLOWCHART AND
PSEUDOCODE
IF STATEMENT IN C
FLOWCHART
Pseudo code Start
Start
Input score(70)
If score>= 50 Input score
print Well
done,your score YES
is 70 If
score Output Well done ,
End if
>=50 score = 70
Print this is
selection only NO
statement Output this is
Stop single selection
statement
Stop
// Program to display remark well done if the score entered is greater than 50.
#include <stdio.h>
int main() {
int score; Output for s core of 90
return 0;
}
Output Fail
Stop
printf("PASS");
}
else {
printf(“FAIL”);
}
return 0;
}
Stop
Output
tax_computed_amount
Stop
Succeeding with Technology, By Wrickly John Kebaso : Republic of Kenya 13
Two-way selection statements : using If-else
#include <stdio.h>
int main ()
{ OUTPUT FOR 25000/=
scanf(“%d”,&amount);
// check the condition
if( amount >= 25000 )
{
// if condition is true then print the following
tax_computed_amount= (25000+(25000*7.5)/100));
printf(“Computed amount plus tax is: %d" ,tax_computed_amount);
else
}
tax_computed_amount= (25000+(25000*5.0)/100));
printf(“Computed amount plus tax is: %d" ,tax_computed_amount);
}
return 0;
}
OUTPUT
You are not eligible for voting
Stop
#include <stdio.h>
int main()
{
int age;
printf("Enter your age:"); OUTPUT FOR age 17
scanf("%d",&age);
if(age >=18){ You are not eligible for voting
printf("You are eligible for voting"); OUTPUT FOR age 19
}
else You are eligible for voting
{
printf("You are not eligible for voting");
}
return 0;
}
IF THEN ELSE IF
STATEMENTS IN C
Score Message
>= 90 Got A
passed
>= 80 Got A
passed
>= 70 Got B
passed
>= 60 Got C
passed
>= 50 Got D
passed
>=40 Got E
Failed
Else Got INVALID GRADE
Confirm with examination office
Stop
Succeeding with Technology, By Wrickly John Kebaso : Republic of Kenya 19
#include <stdio.h>
int main(){
int mark;
80 -100 DISTINCTION
60 - 69 CREDIT
50 - 59 PASS
40 - 49 WEAK PASS
0 - 39 FAIL
Case 0 – OUTPUT
39 You got an E Break
You FAILED
OUTPUT
Default INVALID GRADE Break
Stop
Succeeding with Technology, By Wrickly John Kebaso : Republic of Kenya 23
C program to illustrate using range in switch case
// C program to illustrate
// using range in switch case
#include <stdio.h> Role of break key word
int main()
{
int score;
Printf("Enter Your Score for STRUCTURED PROGRAMMING\n”);
scanf(“%d”,&score);
switch (score)
{
case 70 ... 100:
printf(“DISTINCTION”);
break;
case 60 ... 69:
printf(“CREDIT”);
break;
case 50 ... 59:
printf(“PASS”);
break;
case 40 ... 49:
printf(“WEAK PASS”);
break; OUTPUT FOR score 85
case 0... 39:
printf(“FAIL”); DISTNCTION
break;
OUTPUT FOR score 39
default:
FAIL
printf(“SCORE NOT IN RANGE”);
break;
}
OUTPUT FOR score 120
return 0;
SCORE NOT IN RANGE
}
Write a program that will ask the user to enter his or age and then enter the
gender, the program checks the age entered and the gender , if the age is equal
to or above 18yrs and the gender is “famale” , the program display “You are
eligible for voting” otherwise the program will display “You are not
eligible for voting”
End
Succeeding with Technology, By Wrickly John Kebaso : Republic of Kenya 27
NESTED IF CONCEPT IN C
#include <stdio.h>
int main()
{
int age;
string gender;
printf("Enter your age:");
scanf("%d",&age);
OUTPUT FOR age 17, gender
printf("Enter your gender:");
male
scanf("%6s",&gender);
You are not eligible for voting
if(age >=18){
// nested if OUTPUT FOR age 19, gender
if(gender=“famale”) { female
printf("You are eligible for voting"); You are eligible for voting
}
}
else
}
printf("You are not eligible for voting");
}
return 0;
}
C PROGRAM TO DETERMINE ELIGIBILITY OF A VOTER IN TERMS OF AGE