My money Earning Sites
Programs
C Language Programs with Algorithms and Flowcharts
Step 1: Begin
Step 2: Read a, b, c
Step 3: s = (a + b + c)/2
Step 3: area = √ (s (s-a) (s-b) (s-c))
Step 4: Print area
Step 5: End
Flowchart
Program
/*calculate the area of a triangle using three sides */
#include
#include
#include
void main()
{
float area, a, b, c ,s;
clrscr();
printf ("enter three sides of a triangle ");
scanf ("%f%f%f",&a,&b,&c);
s = (a + b + c)/2;
area=sqrt( s * (s-a) * (s-b) * (s-c));
printf ("Area of a triangle is %f", area);
}
Illustration of the program:
Variables area is used for area of a triangle, s as parameter and a, b, c are used for three sides of triangle .
If you entered , 1.5 2 2.5 as a, b, c, s = (1.5 + 2 + 2.5)/2=3.0000,
then area = √( 3 * (3 - 1.5) * (3 - 2) * (3 - 2.5))
= √ 2.25
= 1.5
So, the output is
Area of a triangle is 1.5
Algorithm
Step 1: Begin
Step 2: Read a, b
Step 3: t = a
Step 4: a = b
Step 5: b = t
Step 6: Print a, b
Step 7: End
Flowchart
Program
/*swapping two numbres*/
#include
#include
void main()
{
int a,b,t;
clrscr();
printf ("Enter two values");
scanf("%d%d",&a,&b);
printf ("Before swapping A=%d, B=%d",a,b);
t = a;
a = b;
b = t;
printf ("After swapping A=%d, B=%d", a, b);
}
Illustration of the program:
Variables a, b are used to store two integer values and t is temporary variable.
If you entered 4 6, 4 is assigned to a and 6 is assigned to b.
the statements,
t = a, t = 4
a = b, a = 6
b = t, b = 4
So, the output is
After swapping A = 6, B = 4
Step 1: Begin
Step 2: Read radius
Step 3: area = 3.14 * radius * radius
Step 4: Print area
Step 5: End
Flowchart
Program
/*calculate the area of a cicle*/
#include
#include
void main()
{
float area,radius;
clrscr();
printf("enter radius of a circle");
scanf("%f",&radius);
area=3.14*radius*radius;
printf("Area of a circle is %f",area);
}
Illustration of the program:
Variables area is used for area of a circle and radius used for radius of a circle.
If you entered 6 as radius, area of a circle is 3.14 * 6 * 6 = 113.04
So, the output is
Area of a circle is 113.040000
Algorithm
Step 1: Begin
Step 2: Read b, h
Step 3: area = b * h / 2
Step 4: Print area
Step 5: End
Flowchart
Program
/*calculate the area of a triangle using base and height */
#include
#include
void main()
{
float area, b, h;
clrscr();
printf ("enter base and height of a triangle ");
scanf ("%f%f",&b,&h);
area=b * h / 2;
printf ("Area of a triangle is %f", area);
}
Illustration of the program:
Variables area is used for area of a triangle and b, h used for base and height of a triangle respectively.
If you entered 6 as base and 7.5 as height, area of a triangle is 6 * 7.5 / 2 = 22.5
So, the output is
Area of a triangle is 22.5
Algorithm
Step 1: Begin
Step 2: Read a, b
Step 3: a = a + b
Step 4: b = a - b
Step 5: a = a - b
Step 6: Print a, b
Step 7: End
Flowchart
Program
/*swapping two numbres*/
#include
#include
void main()
{
int a,b;
clrscr();
printf ("Enter two values");
scanf("%d%d",&a,&b);
printf ("Before swapping A=%d, B=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf ("After swapping A=%d, B=%d", a, b);
}
Illustration of the program:
Variables a, b are used to store two integer values.
If you entered 4 6, 4 is assigned to a and 6 is assigned to b.
the statements,
a = a + b, a = 4 + 6 = 10
b = a - b, b = 10 - 4 = 6
a = a - b, a = 10 - 6 = 4
So, the output is
After swapping A = 6, B = 4