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

Lab Manual #4

Uploaded by

nasrinara30
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)
21 views

Lab Manual #4

Uploaded by

nasrinara30
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/ 3

BGMEA University of Fashion and Technology

Department of Textile Engineering


Course Code: CSE1102
Course Title: Introduction to Computer & Programming Techniques

Lab Exercise – #4
Objective(s):
To understand the programming using Loop & nested loop Statements (for, while, do-while)
Program: Write a program to print positive integers from 1 to 10.
Sample Code:
1. //Using FOR LOOP
2. #include<stdio.h>
3. void main()
4. {
5. int i;
6. for(i=1; i<=10;i++)
7. printf(“%d \n”, i);
8. }

1. //Using WHILE LOOP


2. #include<stdio.h>
3. void main()
4. {
5. int i=1;
6. while(i<=10)
7. {
8. printf(“%d \n”, i);
9. }
10. i++;
11. }

1. //Using DO-WHILE LOOP


2. #include<stdio.h>
3. void main()
4. {
5. int i=1;
6. do
7. {
8. printf(“%d \n”, i);
9. i++;
10. }while(i<=10);
11. }

Sample Output:

1 2 3 4 5 6 7 8 9 10

1
Sample Programs
(Students are to code the following programs in the lab and show the output to instructor/course
teacher)
Instructions:
1. Write comment to make your programs readable.
2. Use descriptive variables in your programs (Name of the variables should show their
purposes)
Programs List:
1. Write a program to count number of digits in a given integer.
2. Write a program to reverse a given integer.
3. Write a program to print the sum of digits of a number using for loop.
4. Write a program to check whether a number is Palindrome or not.
5. Write a program to generate Fibonacci series.
6. Write a program to find GCD (greatest common divisor or HCF) and LCM (least common
multiple) of two numbers.
Program: Write a program to display the following pattern.
*
**
***
****
*****
Sample Code:
1. #include<stdio.h>
2. void main()
3. {
4. int i,j;
5. for(i=1; i<=5;i++)
6. {
7. for(j=1;j<=i;j++)
8. {
9. printf(“*”);
10. }
11. printf(“\n”);
12. }
13. }

2
7. Write programs to display each of the following patterns.
(i)
(ii) (iii) (iv)
***** 1 1 A
**** 22 12 AB
*** 333 123 ABC
** 4444 1234 ABCD
* 55555 12345 ABCDE
(v) (vi) (viii)
(vii)
* ********* ABCDEF
1
ABCDE
*** ******* 121
ABCD
***** ***** 12321
ABC
******* *** 1234321
AB
123454321
********* * A
(ix)
1
123
12345
123
1

You might also like