You are on page 1of 8

University of Sargodha

Mandi Bahauddin campus

LAB Sheet #1

C Lab Report Submitted By:

Name: M Umar

Roll No: BSSE-F17-18

Submitted To:

Department of CS & IT University of Sargodha M.B.Din

Lab Date:2 January 2018 Marks & Signature

Submission Date: 16th January 2018

1
Lab #1

Program No. 1
Title:
Write a program to display “hello world” in C.
Problem Analysis:
It is required to get output of a Hello World using printf() function.
Input variables Processing Output variables Header files
variables
printf () stdio.h

Algorithm:
1. Start
2. Print Hello World
3. Stop
Code:
#include<stdio.h>
Int main(void)
{
Printf(“Hello World!\n”);
return 0;
}
Output:
Hello World!

Program No. 2
Title:

Write a program to add two numbers (5&7) and display its sum.
Problem Analysis:
Based on the problem it is required to print the sum of two numbers which are given.
First declare three integers and assign them value and then calculate the sum and
display on the screen.

2
Input variables Processing Output variables Header files
variables
int a,b,sum printf() -------- stdio.h

Algorithm:
1. Start
2. Define variable (a,b,sum)
3. Assign value to variables (a,b)
4. Calculate sum as sum=a+b
5. Display the sum
6. Stop
Code:
#include<stdio.h>
int main (void)
{
int a,b;
int sum;
a=5;
b=7;
sum = a + b;
printf("Sum = %d", sum);
return 0;
}
Output:
Sum = 12

Program No. 3
Title:
Write a program to multiply two numbers (10&8) and display its product.
Problem Analysis:

3
According to the problem we need to multiply two numbers which we assign to declared
variables and display their result using printf() function
Input variables Processing Output variables Header files
variables
int a,b,multiply printf() stdio.h

Algorithm:
1. Start
2. Define variables (a,b,multiply)
3. Assign value to (a,b)
4. Multiply both variables
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main(void)
{
int a,b;
int multiply;
a=10;
b=8;
multiply = a*b;
printf("The product is %d", multiply);
return 0;
}
Output:
The product is 80

Program No. 4
Title:

Write a program to calculate area of a circle having its radius (r=5).


Problem Analysis:

4
According to the problem it is required to define two float variables and then assign
them value. Use a formula to calculate the area of a circle and print the value on the
screen.
Input variables Processing Output variables Header files
variables
float radius printf() ------- stdio.h
float area

Algorithm:
1. Start
2. Define variables (radius, area)
3. Assign value to variables
4. Calculate values
5. Display the result
6. Stop

Code:
#include<stdio.h>
int main()
{
float radius;
float area;
radius = 5;
area = 3.14*radius*radius;
printf("The area is = %.2f", area);
return 0;
}
Output:
The area is = 78.50

Program No. 5
Title:

5
Write a program to calculate area of an ellipse having its axes (minor=4cm,
major=6cm).
Problem Analysis:
According to the problem it is required to calculate the area of an ellipse having axis
minor=4cm and major=6cm.First define four variables assign the values given 4cm and
6cm to minor and major. Apply the formula of ellipse and display the result.
Input variables Processing Output variables Header files
variables
int minor; printf() ------- stdio.h
int major;
float pi;
float ellipse;

Algorithm:
1. Start
2. Define variables (minor ,major, pi)
3. Assign values to variables
4. Applied formula of ellipse
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main(){
int minor;
int major;
float pi;
float ellipse;
minor = 4;
major = 6;
pi = 3.14;
ellipse = pi * minor * major;
printf("area of ellipse is = %.2f", ellipse);
return 0;
}
Output:

6
Area of ellipse is = 75.36

Program No. 6
Title:

Write a program to calculate simple interest for a given P=4000, T=2, R=5.5. (I =
P*T*R/100).
Problem Analysis:
According to the problem it is required to calculate simple interest for P,T,R and divide
them with 100 which is declared to i, assign the values to P,R and T and calculate them
and display the result.
Input variables Processing Output variables Header files
variables
int p; printf() ------- stdio.h
int t;
float r;
int div;
int i;
Algorithm:
1. Start
2. Define variables (p, t, r, i)
3. Assign values to variables
4. Calculate values
5. Display the result
6. Stop
Code:
#include<stdio.h>
int main ()
{
int p=4000;
int t=2;
float r=5.5;
int div=100;
int i;
i = p*t*r/100;
printf("The result is = %d", i);
return 0;}

7
Output: The result is = 440

You might also like