Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

C programs

Rating
-
Sold
-
Pages
39
Uploaded on
10-04-2024
Written in
2023/2024

Nothing

Institution
Course

Content preview

CS4208-Programming in C Laboratory 2022-2023
C Program Using Simple Statement and Expressions

EX.No 1a Calculate Area and Circumference of Circle

Aim:
To write a C program to calculate Area and Circumference of Circle.

Algorithm:
Step 1: Start
Step 2: Declare variables radius, area, circum in float type
Step 3: Read radius of circle as radius
Step 4: Calculate area using the expression: area = 3.14 * radius * radius
Step 5: Calculate circumference using the expression: circum=2*3.14*radius
Step 6: Print area and circum
Step 7: Stop
Program:
#include<stdio.h>
int main()
{
float radius, area,circum;
printf("\nEnter the radius of Circle : ");
scanf("%f", &radius);
area = 3.14 * radius * radius;
circum=2*3.14*radius;
printf("\nArea of Circle : %.2f", area);
printf("\nCircumference of Circle : %.2f", circum);
return (0);
}
Output:
Enter the radius of Circle : 5
Area of Circle : 78.50
Circumference of Circle : 31.40
Result:
Thus, the C program to calculate Area and Circumference of Circle was written
executed and the output was verified successfully.

EX.No 1b Simple Interest Calculation
Aim:
To write a C program to calculate simple interest.
Algorithm:
Step 1: Start
Step 2: Declare variables for Principal amount, Rate of interest, time
Step 3: Read Principal amount, Rate of interest, time
Step 4: Calculate interest amount using the expression amt=(p*r*t)/100
Step 5: Print Simple interest as amt
Step 6: Stop

St.Joseph’s Institute of Technology Page 1 of 39

,CS4208-Programming in C Laboratory 2022-2023
Program:
#include<stdio.h>
int main()
{
int p,r,t,amt;
printf("Enter Principle amount, Rate of interest & time: \n");
scanf("%d%d%d",&p,&r,&t);
amt=(p*r*t)/100;
printf("Simple interest = %d",amt);
return 0;
}

Output:
Enter Principle amount, Rate of interest & time:
20000
6
2
Simple interest = 2400

Result:
Thus, the C program to calculate Simple Interest was written executed and the
output was verified successfully.




St.Joseph’s Institute of Technology Page 2 of 39

,CS4208-Programming in C Laboratory 2022-2023

Scientific Problem-Solving using Decision Making and Looping

Ex No 2a Largest of Three number

Aim:
To write a C program to find the largest of three numbers using if...else if.

Algorithm:
Step 1. Read the values of x, y and z.
Step 2. If x is greater than y and x is greater than z then print x is greatest, otherwise
go to step 3.
Step 3. If y is greater than z then print y is greatest, otherwise go to step 4.
Step 4. display z is greatest.

Program:
#include<stdio.h>
int main()
{
int x,y,z;
printf("Enter the values for x,y and z \n");
scanf("%d%d%d",&x,&y,&z);
if((x>y)&& (x>z))
printf(" %d is greatest",x);
else if (y>z)
printf ("%d is greatest",y);
else
printf("%d is greatest",z);
return 0;
}

Output:

Run1:
Enter the values for x, y and z
25
46
22
46 is greatest

Run2:
Enter the values for x, y and z
75
46
22
75 is greatest

St.Joseph’s Institute of Technology Page 3 of 39

, CS4208-Programming in C Laboratory 2022-2023

Ex NO 2b Leap Year or Not

Aim:
To write a C program to check whether the given year is leap year or not.

Algorithm:
Step 1. Get the input year from the user to check for leap year.
Step 2. If the year is evenly divisible by 4, go to step 3. Otherwise, go to step 6.
Step 3. If the year is evenly divisible by 100, go to step 4. Otherwise, go to step 5.
Step 4. If the year is evenly divisible by 400, go to step 5. Otherwise, go to step 6.
Step 5. The year is a leap year (it has 366 days).
Step 6. The year is not a leap year (it has 365 days).

Program:
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}

Output:
Run1:
Enter a year: 1900
1900 is not a leap year.
Run2:
Enter a year: 2004
2004 is a leap year.

St.Joseph’s Institute of Technology Page 4 of 39

Written for

Institution
Course

Document information

Uploaded on
April 10, 2024
Number of pages
39
Written in
2023/2024
Type
OTHER
Person
Unknown

Subjects

$8.29
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
ambrishjeyan

Get to know the seller

Seller avatar
ambrishjeyan St.Joseph’s institute of technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions