C PROGRAMS
WEEK 2
PROGRAM-5
5. Write a C Program to read the radius of a circle, calculate
its area and display it.
Algorithm
1. Start
2. Define the constant pi as 3.141592.
3. Declare two floating-point variables: radius and area.
4. Prompt the user to enter the radius of the circle.
5. Read the radius from the user.
6. Calculate the area using the formula:
7. area = pi * radius * radius
8. Print the radius and the area, both with precision up to two
decimal places.
9. End
Pseudo Code
START
Define constant pi = 3.141592
Declare float radius, area
PRINT "Enter Radius of Circle: "
READ radius
area = pi * radius * radius //Calculate the area of the circle
PRINT "The area of Circle with radius " + radius + " is: " + area
// Display radius and area
END
Program
#include <stdio.h>
#define pi 3.14
int main()
{
float radius,area;
printf("Enter Radius of Circle:\n");
scanf("%f",&radius);
area=pi*radius*radius; //Precision of the radius and area in
this program is upto two decimal places
printf("The area of Circle with radius %0.2f is:
%0.2f",radius,area);
return 0;
}
PROGRAM-6
6. Write a C Program read p, n, r and calculate Simple Interest.
Algorithm
1. Start
2. Declare four floating-point variables: principle, time, rate, and
SI (Simple Interest).
3. Prompt the user to enter the principle (amount).
4. Read the principle from the user.
5. Prompt the user to enter the time (in years).
6. Read the time from the user.
7. Prompt the user to enter the rate (percentage).
8. Read the rate from the user.
9. Calculate the Simple Interest (SI) using the formula:
SI = (principle * time * rate) / 100
10. Print the calculated Simple Interest.
11. End
Pseudo Code
START
Declare float principle, time, rate, SI
PRINT "Enter principle (amount): "
READ principle
PRINT "Enter time: "
READ time
PRINT "Enter rate: "
READ rate
SI = (principle * time * rate) / 100 //Calculate Simple Interest
PRINT "Simple Interest = " + SI //Display the Simple Interest
END
Program
#include<stdio.h>
int main()
{
float principle, time, rate, SI;
printf("Enter principle amount: ");
scanf("%f", &principle);
printf("Enter time: ");
scanf("%f", &time);
printf("Enter rate: ");
scanf("%f", &rate);
SI = (principle * time * rate) / 100;
printf("Simple Interest = %f", SI);
return 0;
}
PROGRAM-7
7. Write a C program to check whether a number is even or odd.
Algorithm
1. Start
2. Declare two integer variables: num and rem.
3. Prompt the user to enter an integer.
4. Read the integer from the user and store it in num.
5. Calculate the remainder when num is divided by 2:
6. rem = num % 2
7. If the remainder (rem) is 0, print that the number is even.
8. Otherwise, print that the number is odd.
9. End
Pseudo Code
START
Declare integer num, rem
PRINT "Enter an integer: "
READ num
rem = num % 2 // Calculate remainder when divided by 2
IF rem == 0 THEN
PRINT num + " is an even integer"
ELSE
PRINT num + " is an odd integer"
ENDIF
END
Program
#include<stdio.h>
int main()
{
int num, rem;
printf("Enter an integer : ");
scanf("%d",&num);
rem = num %2;
if(rem ==0)
printf("%d is an even integer\n", num);
else
printf("%d is an odd integer\n", num);
return 0;
}
PROGRAM-8
8. Write a C program to check and print whether a user is eligible
to vote or not.
Algorithm
1. Start
2. Declare an integer variable age.
3. Prompt the user to enter their age.
4. Read the age from the user and store it in age.
5. Check if age is greater than or equal to 18:
• If true, print "Eligible to Vote".
• Otherwise, print "Not Eligible to Vote".
6. End
Pseudo Code
START
Declare integer age
PRINT "Enter the Age: "
READ age
IF age >= 18 THEN
PRINT "Eligible to Vote"
ELSE
PRINT "Not Eligible to Vote"
ENDIF
END
Program
#include <stdio.h>
int main()
{
int age;
printf("\nEnter the Age:");
scanf("%d",&age);
if(age>=18)
printf(“\nEligible to Vote”);
else
printf("\nNot Eligible to Vote”);
return 0;
}