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

CSE1202 Structured Programming Lab ULAB

The document is a lab report for the Structured Programming Lab course, detailing various C programming assignments. Each problem includes a problem statement, code snippets, algorithms, and conclusions about the program's functionality and correctness. The report covers topics such as calculating circle properties, employee salary, day conversion, arithmetic operations, average calculation, and character manipulation.

Uploaded by

balihip991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CSE1202 Structured Programming Lab ULAB

The document is a lab report for the Structured Programming Lab course, detailing various C programming assignments. Each problem includes a problem statement, code snippets, algorithms, and conclusions about the program's functionality and correctness. The report covers topics such as calculating circle properties, employee salary, day conversion, arithmetic operations, average calculation, and character manipulation.

Uploaded by

balihip991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Course Code: CSE1202

Course Title: Structured Programming Lab


Section: 03
Semester: Spring 2025

Lab Report 01

Submitted to:
Jannatul Ferdous Ruma
Lecturer
Department of Computer Science and Engineering (CSE)
ULAB School of Science & Engineering
University of Liberal Arts Bangladesh

Submitted by:

Name:

Submission Date: 12/02/2025

1|Page
Problem Statement-01:
Write a C program to enter the radius of a circle and find its circumference and
area. Note that, Circumference = 2 x π x radius, Area = π x (radius)2, and
assume π=3.1416
Input: 2
Output: 12.56
Code Snippet:

#include <stdio.h>
#include <stdlib.h>

#define PI 3.1416

int main()
{
float radius, circumference, area;
printf("Enter the radius of a circle: ");
scanf("%f", &radius);
circumference = 2 * PI * radius;
area = PI * radius * radius;
if(radius > 0)
{
printf("Circumference: %.2f, Area: %.2f", circumference,
area);
}
else
{
printf("Invalid value of radius.");
}

return 0;
}

2|Page
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Read the value of radius
Step 3: circumference = 2 x PI x radius, area = PI x radius x radius
Step 4: If radius greater than 0 then go to step 5 else go to step 6
Step 5: Write the value of circumference and area
Step 6: Write radius value is invalid
Step 7: End

3|Page
Conclusion:

The program correctly calculates the circumference and area of a circle based
on the given radius. It also checks for invalid input and displays an error
message if the radius is zero or negative. The program is executing correctly
and returns expected results.

Problem Statement-02:
Write a C program to calculate and display the total salary of an employee
considering that total salary is the sum of basic salary and house rent. The
program must ask the user for the basic salary and percentage of basic salary
which determines the house rent.
Input: 25000 10
Output: 27500
Code Snippet:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float basicSalary, percentageHouseRent, salary, percentage;
printf("Enter your basic salary: ");
scanf("%f", &basicSalary);
printf("Enter the percentage of house rent of basic salary: ");
scanf("%f", &percentageHouseRent);
percentage = (percentageHouseRent / 100) * basicSalary;
salary = basicSalary + percentage;
printf("Your salary is: %.2f", salary);

return 0;
}

4|Page
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Declare four floating point variables: basicSalary,
percentageHouseRent, salary, percentage
Step 3: Ask the user to enter their basicSalary
Step 4: Read the input of basicSalary
Step 5: Ask the user to enter the percentage of house rent
Step 6: Read and store the house rent percentage
Step 7: Calculate the house rent amount:
percentage = (percentageHouseRent / 100) * basicSalary
Step 8: Calculate the salary
salary = basicSalary + percentage
Step 9: Write the salary as output
Step 10: End

5|Page
Conclusion:

This program calculates the total salary by adding the house rent to the basic
salary. It takes the basic salary and house rent percentage as input, calculates the
house rent, and adds it to the salary. The program runs correctly and gives the
expected output based on the given inputs. he program runs properly and is easy
to use for salary calculations.

Problem Statement-03:
Write a C program that takes number of days as input, and then converts it into
years and days, and displays the results. Assume that, 1 year = 365 days.
Input: 735
Output: 2 years 5days
Code Snippet:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int days, year;
printf("Enter days: ");
scanf("%d", &days);
if(days > 365)
{
year = days / 365;
days = days % 365;
printf("%dyears %ddays", year, days);
}
else
{
printf("%d", days);
}

return 0;
}

6|Page
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Declare two integer type variables: days, year
Step 3: Ask the user to enter the number of days
Step 4: Read and store the input in days
Step 5: Check conditions if days is more than 365 than go to step 6
else go to step 7
Step 6: Calculate the number of years: year = days / 365
Calculate the remaining days: days = days % 365
Write the value of years and remaining days
Step 7: Write the days as it is if it is less than 365
Step 8: End

Conclusion:

This program converts the given number of days into years and remaining days
if the input is more than 365. If the days are less than 365, it simply displays the
number of days. The program runs correctly and provides accurate results based
on the input.

7|Page
Problem Statement-04:
Take two inputs from user and find out sum, subtract multiplication and
division.
Input: 8 2
Output: Sum=10, Subtract=6, Multiplication= 16, Division = 4
Special Condition: If you divide by 0, it will show “not possible to divide by 0”
Code Snippet:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float num1, num2, sum, sub, multi, div;
printf("Enter two numbers: ");
scanf("%f %f", &num1, &num2);
sum = num1 + num2;
sub = num1 - num2;
multi = num1 * num2;
div = num1 / num2;
if(num2 == 0)
{
printf("Sum = %.2f, Subtract = %.2f, Multiplication = %.2f,
Division = It's not possible to divide by 0", sum, sub, multi);
}
else
{
printf("Sum = %.2f, Subtract = %.2f, Multiplication = %.2f,
Division = %.2f", sum, sub, multi, div);
}

return 0;
}

8|Page
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Declare six float type variables: num1, num2, sum, sub, multi, div
Step 3: Ask the user to enter two numbers
Step 4: Read and store the inputs in num1and num2
Step 5: Perform calculation:
Addition: sum = num1 + num2
Subtraction: sub = num1 - num2
Multiplication: multi = num1 * num2
Division: div = num1 / num2
Step 6: Check condition if num2 is 0:
if yes: Display the sum, subtraction, and multiplication, but show a
message that division by zero is not possible
if no: Display the sum, subtraction, multiplication, and division
Step 7: End

9|Page
Conclusion:

This program takes two numbers as input and performs addition, subtraction,
multiplication, and division. It correctly handles division by zero by displaying
a message instead of an invalid result. The program runs properly and gives the
expected output based on the input values.

Problem Statement-05:
Find out average of four numbers
Input: 5 8 4 6
Output: Average = 5.75
Code Snippet:

#include <stdio.h>
#include <stdlib.h>

int main()
{
float num1, num2, num3, num4, avg;
printf("Enter four numbers: ");
scanf("%f %f %f %f", &num1, &num2, &num3, &num4);
avg = (num1 + num2 + num3 + num4) / 4;
printf("Average: %.2f", avg);

return 0;
}

10 | P a g e
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Declare five float type variables: num1, num2, num3, num4, avg
Step 3: Ask the user to enter four numbers
Step 4: Read and store the inputs in num1, num2, num3and num4
Step 5: Calculate the average using the formula:
avg = (num1 + num2 + num3 + num4) / 4
Step 6: Display the average with two decimal places
Step 7: End

Conclusion:

This program takes four numbers as input and calculates their average. It
correctly performs the calculation and displays the result with two decimal
places. The program runs properly and gives the expected output based on the
input values.

11 | P a g e
Problem Statement-06:
Write a program in C that computes the value for z, where z = x^3 +
3*(x^2)*(y^4)+y^2. The value of x and y should be taken from the user. Use
pow() function to solve this problem
Code Snippet:

#include<stdio.h>
#include<stdlib.h>

int main()
{
float x, y, z;
printf("Enter two numbers: ");
scanf("%f %f", &x, &y);
z = pow(x, 3) + 3 * pow(x, 2) * pow(y, 4) + pow(y, 2);
printf("z = %.2f", z);

return 0;
}

Output Snippet:

12 | P a g e
Algorithm:

Step 1: Start
Step 2: Declare three floating type variables: x, y, and z
Step 3: Ask the user to enter two numbers
Step 4: Read and store the two numbers in x and y
Step 5: Calculate the value of z using the formula:
z = x³ + 3 * x² * y⁴ + y²
Step 6: Display the value of z with two decimal places
Step 7: End

Conclusion:

This program takes two numbers as input and calculates the value of z using a
mathematical formula. It correctly performs the calculations and displays the
result with two decimal places. The program runs properly and gives the
expected output based on the input values.

13 | P a g e
Problem Statement-07:
Print the value of y for given x=2 & z=4 and analyze the output.
a. y = x>z;
b. y= x>z? x:z;
c. y = x&z;
Code Snippet:

#include<stdio.h>
#include<stdlib.h>

int main()
{
int x = 2, y, z = 4;
printf("y = x > z is %d\n", y = x > z);
printf("y= x > z ? x : z is %d\n", y= x > z ? x : z);
printf("y = x & z is %d\n", y = x & z);

return 0;
}

Output Snippet:

14 | P a g e
Algorithm:

Step 1: Start
Step 2: Declare three integer type variables: x = 2, y, and z = 4
Step 3: Evaluate and display the result of the expression y = x > z:
It checks if x is greater than z and stores 1 (true) or 0 (false) in y
Step 4: Evaluate and display the result of the ternary operation y = x > z ? x : z:
If x > z is true, y takes the value of x; otherwise, it takes the value of z
Step 5: Evaluate and display the result of the bitwise AND operation y = x & z:
Performs a bitwise AND operation between x and z and
stores the result in y
Step 6: End

Conclusion:

This program shows how relational, ternary, and bitwise operations work with
numbers. It checks if x is greater than z, chooses a value using the ternary
operator, and does a bitwise AND operation. The program works correctly and
gives the right results.

15 | P a g e
Problem Statement-08:
Print the value of y for given x=2 & y=4 and analyze the output.
a. y = =x; b. y>= x; c x>=y;
d. x>=y && x==2; e. x>=y || x==2 ; f. x<=y && x==2
Code Snippet:

#include<stdio.h>
#include<stdlib.h>

int main()
{
int x = 2, y = 4;
printf("y == x is %d\n", y == x);
printf("y >= x is %d\n", y >= x);
printf("x >= y is %d\n", x >= y);
printf("x >= y && x == 2 is %d\n", x >= y && x == 2);
printf("x >= y || x == 2 is %d\n", x >= y || x == 2);
printf("x <= y && x == 2 is %d\n", x <= y && x == 2);

return 0;
}

Output Snippet:

16 | P a g e
Algorithm:

Step 1: Start
Step 2: Declare two integer variables: x = 2 and y = 4.
Step 3: Check and display if y is equal to x (y == x).
Step 4: Check and display if y is greater than or equal to x (y >= x).
Step 5: Check and display if x is greater than or equal to y (x >= y).
Step 6: Check and display the result of the logical AND operation
(x >= y && x == 2).
Step 7: Check and display the result of the logical OR operation
(x >= y || x == 2).
Step 8: Check and display the result of the logical AND operation
(x <= y && x == 2).
Step 9: End

Conclusion:

This program checks and displays the results of comparison and logical
operations using two numbers. It compares values using ==, >=, and <= and
evaluates logical AND (&&) and OR (||) conditions. The program runs correctly
and gives the expected results.

17 | P a g e
Problem Statement-09:
Write a C program to take a letter from the English alphabet as input and
display both the previous and the next letters with ASCII codes. Assume that
input will always be chosen from B to Y or b to y.

Code Snippet:

#include<stdio.h>
#include<stdlib.h>

int main()
{
char alpha;
int prev, after;
printf("Enter a letter: ");
scanf("%c", &alpha);
prev = alpha - 1;
printf("Previous letter with ASCII: %c %d", prev, prev);
after = alpha + 1;
printf("\nNext letter with ASCII: %c %d", after, after);

return 0;
}

18 | P a g e
Output Snippet:

Algorithm:

Step 1: Start
Step 2: Declare a character variable alpha and two integer variables
prev and after.
Step 3: Ask the user to enter a letter.
Step 4: Read and store the input letter in alpha.
Step 5: Find the previous letter by subtracting 1 from alpha (prev = alpha - 1).
Step 6: Display the previous letter along with its ASCII value.
Step 7: Find the next letter by adding 1 to alpha (after = alpha + 1).
Step 8: Display the next letter along with its ASCII value.
Step 9: End

Conclusion:

This program takes a letter as input and finds the previous and next letters along
with their ASCII values. It correctly performs the calculations and displays the
expected results.

19 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy