You are on page 1of 17

PRESTON UNIVERSITY KOHAT, ISLAMABAD CAMPUS

DEPARTMENT OF COMPUTER SCIENCES

LAB SHEET # 1

PROGRAMMING FUNDAMENTALS LAB REPORT


SUBMITTED BY
REGN NO: 1442-320007
NAME: M WAQAS KHALIL

SUBMITTED TO

DEPARTMENT OF COMPUTER SCIENCE

Marks & Signature


Lab Date:
Submission Date: 03 Feb 2021
[2]
Lab Sheet # 1 Programming Fundamentals

Title:
1. Write a program that will print your mailing address in the following form:

First line : Name


Second line : Door No, Street
Third line : City, Pin code
Algorithm:
a. Start
b. Printed First Line as First Line : Name
c. Printer Second Line as Second Line : Door No, Street
d. Printed Third Line as Third Line : City, Pin Code
e. Stop

Flowchart:

Start

Print Name

Print Door No. and Street

Print City & Pin Code

End

Code:
#include<stdio.h>
main()
{
printf("Name\t\t:\tMuhammad Waqas Khalil");
printf("\nDoor Number, St\t:\tHouse No.53, Street No.2");
printf("\nCity, Pin Code\t:\tRawalpindi Cantt");

Output (Compilation, Debugging & Testing):

Name : Muhammad Waqas Khalil


Door Number, St : House No.53, Street No.2
City, Pin Code : Rawalpindi Cantt
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[3]
Lab Sheet # 1 Programming Fundamentals

Title:
2. Modify the above program to provide border lines to the address
Algorithm:
a. Start
b. Printed ********* on the First Line
c. Printer * at the start of the second line
d. Printed First statement as First Line : Name
e. Printer * at the end of the second line
f. Printer * at the start of the third line
g. Printer Second Line as Second Line : Door No, Street
h. Printer * at the end of the third line
i. Printer * at the start of the fourth line
j. Printed Third Line as Third Line : City, Pin Code
k. Printer * at the end of the fourth line
l. Printed ********* on the last Line
m. Stop

Flowchart:

Start

print Name

print Door no & Street no.

print City & Pin Code

print stars boundry ***

End

Code:
#include<stdio.h>
main()
{
printf("*******************************************************");
printf("\n\n*\tName\t\t:\tMuhammad Waqas Khalil\t*");
printf("\n*\tDoor No, St\t:\tHouse No.53, Street No.2*");
printf("\n*\tCity, Pin Code\t:\tRawalpindi Cantt\t*");
printf("\n\n*******************************************************");

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[4]
Lab Sheet # 1 Programming Fundamentals

}Output (Compilation, Debugging & Testing):


************************************************
 Name : Muhammad Waqas Khalil *
 Door No, St : House No.53, Street No.2 *
 City, Pin Code : Rawalpindi Catt *
*************************************************
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[5]
Lab Sheet # 1 Programming Fundamentals

Title:
3. Write a program using one print statement to print the pattern of asterisks as shown
below :
*
* * * * * * * * *
*

Algorithm:
a. Start
b. Printed * on the First Line after some tabs.
c. Printed * with one tab space on the second line
d. On the third line again a * is printed after some tabs
e. Stop

Flowchart:

Start

print * with spaces & tabs

End

Code:
#include<stdio.h>
main()
{
printf("\t\t *\n*\t*\t*\t*\t* *\t*\t*\t*\n\t\t\t *");

}
Output (Compilation, Debugging & Testing):

*
* * * * * * * *
*

***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[6]
Lab Sheet # 1 Programming Fundamentals

Title:
4. Write a program that will print the following figure using suitable characters.

--------------- --------------
| | | |
| | >>------------------- >> | |
--------------- ---------------

Algorithm:
a. Start
b. Printed -------- after some tabs again printed -------- on the first line.
c. Printed | then after a tab again printed |. Again printed the same for the second square
on the second line
d. Printed | then after a tab again printed | and arrow in the point to second square on the
third line.
e. Printed -------- after some tabs again printed -------- on the last line
f. Stop

Flowchart:

Start

print --------

print |

print >----->

print |

print --------

End

Code:
#include<stdio.h>
main()
{

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[7]
Lab Sheet # 1 Programming Fundamentals

printf("--------\t\t\t--------");
printf("\n|\t|\t\t\t|\t|");
printf("\n|\t|\t>------->\t|\t|");
printf("\n|\t|\t\t\t|\t|");
printf("\n--------\t\t\t--------");
}
Output (Compilation, Debugging & Testing):

---------------- ----------------
| | | |
| | >>------------------- >> | |
| | | |
---------------- ----------------
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[8]
Lab Sheet # 1 Programming Fundamentals

Title:
5. Given the radius of a circle, write a program to compute and display its area. Use a
symbolic constant to define the π value and assume a suitable value for radius.
Algorithm:
a. Start
b. Define variables area, radius with type float,
c. As Pie (π) has standard value i.e 3.14 so assigned pie=3.14 with type float.
d. Asked user to enter the value of radius
e. Calculated the area of circle using formula πr2.
f. Printed the area on the last line
g. Stop

Flowchart:

Start

float area=0.0 , radius = 0.0

read radius

Area = PI x r x r

print area

End

Code:
#include<stdio.h>
#define PI 3.14
main()
{
float area, radius;
printf("Enter the value of radius: ");
scanf("%f", &radius);
area = PI*radius*radius;
printf("The Area of the Circle is %.2f", area);
}Output (Compilation, Debugging & Testing):
Enter the value of radius: 5
The Area of the Circle is 78.50
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[9]
Lab Sheet # 1 Programming Fundamentals

Title:
6. Write a program to output the following multiplication table.

5 x 1 =5
5 x 2 =10
5 x 3 =15
..
..
5 x 10=50
Algorithm:
a. Start
b. Printed first line as 5x1=5
c. Printed all the next lines upto 5x10=50
d. Stop

Flowchart:

Start

Print 5 x 1 = 5

Print 5 x 2 = 10

Print 5 x 3 = 15

Print 5 x 4 = 20

Print 5 x 5 = 25

Print 5 x 6 = 30

Print 5 x 7 = 35

Print 5 x 8 = 40

Print 5 x 9 = 45

Print 5 x 10 = 50

End

Code:
#include<stdio.h>
main()
{
printf("5x1=5");
printf("\n5x2=10");

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[10]
Lab Sheet # 1 Programming Fundamentals

printf("\n5x3=15");
printf("\n5x4=20");
printf("\n5x5=25");
printf("\n5x6=30");
printf("\n5x7=35");
printf("\n5x8=40");
printf("\n5x9=45");
printf("\n5x10=50");
}
Output (Compilation, Debugging & Testing):
5x1=5
5x2=10
5x3=15
5x4=20
5x5=25
5x6=30
5x7=35
5x8=40
5x9=45
5x10=50
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[11]
Lab Sheet # 1 Programming Fundamentals

Title:
7. Given the values of three variables a, b and c, write a program to compute and display
the values of x, where

X= a / (b - c)

Execute your program for the following values:


 a=250, b=85, c=25
 a=300, b=70, c=70
Comment on the output in each case.
Algorithm:
a. Start
b. Define four variable a, b, c and x where a,b & c will be provided by the used and
result will be stored in x.
c. Ask the used to enter the values of a, b & c respectively.
d. Calculate the value to X by using the formula X=a/(b-c)
e. Printed the value of X on the last line
f. Stop

Flowchart:

Start

a=0, b=0, c=0, x=0

read a, b and c

x = a/(b-c)

print x

End

Code:
#include<stdio.h>
main()
{
int a, b, c,x;
printf("Enter the value of a, b & c to print the value of x\n");
scanf("%d %d %d", &a, &b, &c);
x = a/(b-c);
Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[12]
Lab Sheet # 1 Programming Fundamentals

printf("The value of x is %d", x);


}
Output (Compilation, Debugging & Testing):
Enter the value of a, b & c to print the value of x
250
85
25
The value of x is 4
Enter the value of a, b & c to print the value of x
300
70
70
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[13]
Lab Sheet # 1 Programming Fundamentals

Title:
8. Relationship between Celsius and Fahrenheit is governed by the formula

F = (9C/5) + 32
C=5/9 (F-32)

Write a program to convert the temperature


 From Celsius to Fahrenheit and
 From Fahrenheit to Celsius.
Algorithm:
a. Start
b. Define variables f,c, frn, cel
c. Ask user to enter Fahrenheit Temperature
d. Ask used to Enter Celsius Temperature
e. Converted Celsius To Fahrenheit Using formula frn = (9C/5)+32
f. Converted Fahrenheit to Celsius using formula cel =5/9 (F-32)
g. Printed the values of Both Fahrenheit and Celsius
h. Stop

Flowchart:

Start

f=0, c=0, cel=0, frn=0

Read Fahrenheit Temp

Read Celsius Temp

frn = (9*c)/5+32

cel = (f-32)*5/9

Print Celsius when fahrenheit is given

Print fahrenheit when Celsiusis given

End

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[14]
Lab Sheet # 1 Programming Fundamentals

Code:
#include<stdio.h>
main()
{
int f,c ,frn ,cel;
printf("Enter Fahrenheit Temp :");
scanf("%d", &f);
printf("Enter Celsius Temp :");
scanf("%d", &c);
frn = (9*c)/5+32;
cel = (f-32)*5/9;
printf("\nThe Fahrenheit is %d, Celsius Temp is %d", f, cel);
printf("\nThe Celsius is %d, Fahrenheit Temp is %d", c, frn);
}
Output (Compilation, Debugging & Testing):
Enter Fahrenheit Temp :32
Enter Celsius Temp :78
The Fahrenheit is 32, Celsius Temp is 0
The Celsius is 78, Fahrenheit Temp is 172
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[15]
Lab Sheet # 1 Programming Fundamentals

Title:
9. Area of a triangle is given by the formula:

A=sqrt(S(S-a) (S-b)(S-c))

Where a, b and c are sides of the triangle and 2S=a + b + c. Write a program to compute the
area of the triangle given the values of a, b and c.
Algorithm:
a. Start
b. Define variables s, a, b, c, result & area
c. Ask user to enter the value of sides of the triangle to calculate the area
d. Calculated s from the formula given in the question i.e 2S=a+b+c
e. Using the value of s, calculated the result from the formula also given in the question
(s(s-a)(s-b)(s-c))
f. Square root the obtained result to get the area of triangle using math.h (preprocessor
directive)
g. Printed the values of area
h. Stop

Flowchart:

Start

s=0, a=0,b=0,c=0, result=0, area=0

read a, b & c

s=(a+b+c)/2

result = s*(s-a)*(s-b)*(s-c)

area = sqrt(result)

print area

End

Code:
#include<stdio.h>

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[16]
Lab Sheet # 1 Programming Fundamentals

#include<math.h>
main()
{
int s, a, b, c, result, area;
printf("Enter the value of the three sides of triange :\n");
scanf("%d %d %d", &a, &b, &c);
s=(a+b+c)/2;
result = s*(s-a)*(s-b)*(s-c);
area = sqrt(result);
printf("The area of triange is %d", area);
}
Output (Compilation, Debugging & Testing):
Enter the value of the three sides of triange :
5
12
15
The area of triange is 26
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad
[17]
Lab Sheet # 1 Programming Fundamentals

Title:
10. Write a program to display the equation of a line in the form:
ax + by = c
For a=5, b=8 and c=18.
Algorithm:
a. Start
b. Define variables x,y,z
c. Initialize a=5 b=8 and c=18
d. Printed equation of line as ax+by = c
e. Displayed the values in the equation
f. Stop

Flowchart:

Start

a=5,b=8,c=18

x=0, y=0, z=0

print equation of line

End

Code:
#include<stdio.h>
main()
{
int a=5,b=8,c=18;
int x,y,z;
printf("The Equation of line is\n");
printf("%dX + %dY = %d",a,b,c);
}
Output (Compilation, Debugging & Testing):
The Equation of line is
5X + 8Y = 18
***END***

Regn No.1442-320007 Muhammad Waqas Khalil MCS (Eve), Preston University Islamabad

You might also like