Professional Documents
Culture Documents
Theory: Algorithm
The sequence of rules that define how a particular problem can be solved in a finite
sequence of steps is known as an algorithm.
● Refine the algorithm successively to get step by step detailed algorithm that is
very close to a computer language.
Example 1: Write an algorithm to determine a student’s final grade and indicate whether
it is passing or failing. The final grade is calculated as the average of four marks
● if average is below 50
Print “FAIL”
else
Print “PASS”
Detailed Algorithm:
Step 1: Input M1,M2,M3,M4
Print “FAIL”
else
Print “PASS”
Endif
The Flowchart
A schematic representation of a sequence of operations, as in a manufacturing process or
computer program.
The Information system flowcharts show how data flows from source documents through
the computer to final distribution to users.
Program flowcharts show the sequence of instructions in a single program or subroutine.
Different symbols are used to draw each type of flowchart.
Flowchart Symbols:
Problems:
1. To check if the number entered by the user is odd or even.
Flowchart:
Flowchart:
Theory:
#include <stdio.h>
int main()
{
print(“Amanat Kumar, Gurugram”);
return0;
}
Output:
Theory:
#include <stdio.h>
int main()
{
int a,b,sum;
printf("Enter two numbers\n");
scanf("%d,%d",&a, &b);
Sum = a + b;
printf("%d + %d = %d", a, b, sum);
return 0;
}
Output:
void main()
{
int a,b, temp;
printf("enter two intergers\n");
scanf("%d%d", &a, &b);
printf("before swapping \nfirst integer = %d,\nsecond integer = %d\n", a,b); temp=a;
a=b;
b=temp;
printf("after swapping \nfirst integer = %d,\nsecond integer = %d”,a,b);
}
Output:
Aim: write a C program to find the greatest of three using nested if else statement
Theory:
#include <stdio.h>
#include <conio.h>
void main()
{
int n1,n2,n3;
printf(“Enter integers n1,n2,n3\n”);
scanf(“%d%d%d”,&n1,&n2,&n3);
if(n1>n2){
if(n1>n3){
printf(“%d is greatest”,n1);
}
else{
printf(“%d is greatest”,n3);
}
}
else{
if(n2>n3){
printf(“%d is greatest”,n2);
}
else{
printf(“%d is greatest”,n3);
}
}
}
Output: