Algorithm and Flowchart

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ALGORITHS AND FLOW CHARTS

Algorithm to find the sum of all odd numbers less than 100.
Step 1: Start
Step 2: Initialize sum=0
Step 3: Set i=1
Step 4: Repeat steps 4.1 to 4.2 as long as i < 100
Step 4.1: sum = sum + i
Step 4.2: i = i + 2
Step 5: Print sum
Step 6: Stop

Program to find the sum of all odd


numbers less than 100.

#include<stdio.h>
void main()
{
int sum=0, i;
for(i=1;i<100;i=i+2)
{
sum=sum+i;
}
printf("Sum=%d",sum);
}

Algorithm to find the sum of


first n natural numbers.
Step 1: Start
Step 2: Initialize sum=0
Step 3: Read limit and assign it to n
Step 4: Set i=1
Step 5: Repeat steps 5.1 to 5.2 as long as i ≤ n
Step 5.1: sum = sum + i
Step 5.2: i = i + 1
Step 6: Print sum
Step 7: Stop
Algorithm to find the area of a triangle - heron's formula.
Step 1: Start
Step 2: Read length of three sides of a triangle into s1, s2, s3
Step 3: Compute sp = s1+s2+s3/2
Step 4: Compute
Step 5: Print area
Step 6: Stop

Flow Chart to find the area of a triangle - heron's formula.

You might also like