Professional Documents
Culture Documents
Lab Sheet No1
Lab Sheet No1
LAB SHEET # 1
SUBMITTED TO
Title:
1. Write a program that will print your mailing address in the following form:
Flowchart:
Start
Print Name
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");
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
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
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
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
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)
Flowchart:
Start
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
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)
Flowchart:
Start
frn = (9*c)/5+32
cel = (f-32)*5/9
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
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
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