3 G3 LAB Dec 02 2020
3 G3 LAB Dec 02 2020
Applied Sciences
2. Copying Assignment / Using internet During Lab tasks and Marking Proxy will Lead you
to “F” Grade in the Lab. Be very Careful.
3. Use appropriate naming convention for variable name. e.g to calculate the sum of number
variable name can be sum, sum_of_number. Random variable names are not allowed.
4. Lab Tasks must also be submitted in report format too. Sample format is available on
below path. \\172.30.10.24\FacultyShare\Muhammad Yousaf Hamza
Dr\Public\1_CFP_Zero_Sem_2020_22\2_Lab_Assignments
7. Within Lab task must be submitted on below mentioned path till Wednesday, 02-Dec-
2020 (13:30PM)
10. Please note that there is Non- Submission Important Practice Tasks section in this
lab manual, these tasks are not required to be submitted. These tasks are for
practice purpose only. Please note that these important task can be part of quizzes
and exams.
Nested Loop
A loop inside another loop is called a nested loop. The depth of nested loop depends on the
complexity of a problem. We can have any number of nested loops as required. Consider a
nested loop where the outer loop runs n times and consists of another loop inside it. The inner
loop runs m times. Then, the total number of times the inner loop runs during the program
execution is n*m.
Syntax:
The syntax for a nested while loop statement in C programming language is as follows −
while(condition) {
while(condition) {
statement(s);
}
statement(s);
}
The syntax for a nested do...while loop statement in C programming language is as follows −
do {
statement(s);
do {
statement(s);
}while( condition );
}while( condition );
Self-Acivity-Task-01
#include <stdio.h>
int main()
{
int i=1,j;
while (i <= 5)
{
j=1;
while (j <= i )
{
printf("%d ",j);
j++;
}
printf("\n");
i++;
}
Getchar();
Output:
1
12
123
1234
12345
Sample Output:
5
44
333
2222
11111
Home Task 1
Write a program in C to display the first n terms of Fibonacci series. Your program may look like this
Number of terms to display: 10
Fibonacci series up to 10 terms: 0 1 1 2 3 5 8 13 21 34 .
Home Task 2
Write a program in C to print the following pattern.
Home Task 4
Home Task 5
Write a program to compute the sin of x. The user should supply x and a positive integer n. We compute the
sin of x using the series and the computation should use all terms in the series up through the term involving
xn
Home Task 6
Write a program to compute the cosine of x. The user should supply x and a positive integer n. We compute
the cosine of x using the series and the computation should use all terms in the series up through the term
involving xn
cos x = 1 - x2/2! + x4/4! - x6/6! ..
Write a C program to print the given number pattern using for loop.
e^x=1+x/1!+x^2/2!+x^3/3!+...x^n/n!
Try to modify the previous program such that the program prints the following pattern