Green University of Bangladesh Department of Computer Science and Engineering (CSE)
Green University of Bangladesh Department of Computer Science and Engineering (CSE)
Student Details
Name ID
1.
2.
3.
[For Teachers use only: Don’t Write Anything inside this box]
Introduction to Expression in C
1. Write a C Program to Calculate Area of a Square, take length of one side as user
input.
2. Write a C program to enter temperature in °Celsius and convert it into °Fahrenheit.
3. Write a C program to enter temperature in Fahrenheit(°F) and convert it into
Celsius(°C).
4. Write a C program to enter marks of five subjects and calculate total and average
marks.
OBJECTIVES/AIM:
Procedure:
Algorithm:
1. Step 1 : Start
2. Step 2 : Accept as input, the length of the sides of the square, and store the
value in variable side.
3. Step 3 : Calculate the area of the square (a*a) and store in a variable area.
4. Step 4 : Display the area of the square.
5. Step 5 : Stop
Implementation/Code:
#include<stdio.h>
int main()
{
int side, area;
printf("\nEnter the Length of Side : ");
scanf("%d", &side);
area = side * side;
printf("\nArea of Square : %d", area);
return (0);
}
Output:
Answer to the question number 2:
Procedure:
Algorithm:
1. Step 1: Start
2. Step 2: Read the input of temperature in Celsius
3. Step 3: F=(9*C)/5+32
4. Step 4: Print temperature in fahrenheit is F
5. Step 5 :Stop
Implementation/Code:
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
//celsius to fahrenheit conversion formula
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}
Output:
Answer to the question number 3:
Procedure:
Algorithm:
1. Step 1: Start
2. Step 2: Read the input of temperature in fahrenheit
3. Step 3: F=(9*C)/5+32
4. Step 4: Print temperature in celcius is F
5. Step 5 :Stop
Implementation/Code:
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("%.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius);
return 0;
}
Output:
Answer to the question number 4:
Procedure:
Algorithm:
1. Step 1: Srart
2. Step 2: Input marks of five subjects. Store it in some variables say eng, phy,
chem, math and comp.
3. Step 3: Calculate sum of all subjects and store in total = eng + phy + chem +
math + comp.
4. Step 4: Divide sum of all subjects by total number of subject to find average i.e.
average = total / 5 .
5. Step 5: Finally, print resultant values total and average.
Implementation/Code:
#include <stdio.h>
int main()
{
float eng, phy, chem, math, comp;
float total, average;
printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);
total = eng + phy + chem + math + comp;
average = total / 5.0;
printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
return 0;
}
Output: