0% found this document useful (0 votes)
84 views

Green University of Bangladesh Department of Computer Science and Engineering (CSE)

The document is a lab report for an introductory C programming course. It includes 4 questions to write C programs that: 1) Calculate the area of a square, 2) Convert Celsius to Fahrenheit, 3) Convert Fahrenheit to Celsius, and 4) Calculate total and average marks from 5 subjects. For each question, the student provides the algorithm, C code, and output. The report concludes with an analysis discussing how the lab helped the student better understand expressions in C.

Uploaded by

Rakibul Karim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Green University of Bangladesh Department of Computer Science and Engineering (CSE)

The document is a lab report for an introductory C programming course. It includes 4 questions to write C programs that: 1) Calculate the area of a square, 2) Convert Celsius to Fahrenheit, 3) Convert Fahrenheit to Celsius, and 4) Calculate total and average marks from 5 subjects. For each question, the student provides the algorithm, C code, and output. The report concludes with an analysis discussing how the lab helped the student better understand expressions in C.

Uploaded by

Rakibul Karim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Fall, Year: 2021), B.Sc. in CSE (Day)

LAB REPORT NO #02


Course Title: Structured Programming Lab
Course Code: CSE 104 Section: 212DC

Lab Experiment Name: Introduction to Expression in C

Student Details

Name ID
1.
2.
3.

Lab Date : 26th October, 2021


Submission Date : 1st November, 2021
Course Teacher’s Name :

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status


Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
TITLE OF THE LAB EXPERIMENT:

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:

 To be familiar with different data types, operators and expressions in C.


 To learn problem solving techniques using C.

Answer to the question number 1:

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:

Analysis and Discussion:

Based on the focused objectives to understand about different types of expressions in C


program, the additional lab exercise made me more confident towards the fulfilment of
the objectives.

You might also like