Professional Documents
Culture Documents
OBJECTIVE:
This lab will introduce advanced concepts in loops available in C Language Program. At the end of this lab,
you should be able to:
APPARATUS:
Laptop\PC with following tools installed
o Visual Studio Code with C/C++ and Code Runner Extensions
o C/C++ mingw-w64 tools for Windows 10
LAB SUBMISSION:
Create a Visual Studio Code Workspace, Lab_10 and c files (Task_10_1.c to Task_10_10.c) for individual
tasks and add them to Lab_10 workspace.
ITRATION STATEMENTS
Nested Loops
C programming allows to use one loop inside another loop. The following section shows a few examples to
illustrate the concept.
A final note on loop nesting is that you can put any type of loop inside any other type of loop. For example,
a ‘for’ loop can be inside a ‘while’ loop or vice versa.
#include <stdio.h>
void print_triangle(int num) {
// Prints a triangle of asterisks to the console.
for (int i = 0; i < num; i++) {
for (int j = 0; j <= i; j++) {
printf("*");
}
printf("\n");
}
}
int main() {
int num;
printf("Enter a number >> ");
scanf("%d", &num);
// Call the print_triangle() function.
print_triangle(num);
return 0;
}
// End of program
Enter a number >> 5
*
**
Program Output 1
***
****
*****
Enter a number >> 3
*
Program Output 2
**
***
*****
****
***
**
*
Enter the number >> 3
***
Sample Output 2
**
*
Answer:
#include<stdio.h> void print_triangles(int num) { for (int i = 0; i < num; i++) { for (int j = num; j > i; j--) { prin
Answer:
#include <stdio.h> void Stars_format_2(int num) { for (int i = 0; i < num; i++) { for (int j = 0; j <=num-i; j++) {
**
***
****
*****
****
***
**
*
Enter the number >> 3
*
**
Sample Output 2
***
**
*
Answer:
#include <stdio.h> void Stars_format_3(int num) { for (int i = 0; i < num; i++) { for (int j = 0; j <= i; j++) { pri
Answer:
#include <stdio.h> void Print_stars4(int num) { for (int i = 0; i < num; i++) { for (int k = 0; k <= num - i; k++) {
Answer:
#include <stdio.h> void Number_triangle_1(int num) { for (int i = 1; i <= num; i++) { for (int j = 1; j <= i; j++) {
123
Answer:
#include<stdio.h> void Number_triangle_2(int num) { for (int i = 1; i <= num; i++) { for (int j = 1; j <= i; j++) {
Answer:
#include <stdio.h> void Number_Matrix(int a, int b) { int i; for (int j = 1; j <= a; j++) { for (i = 1; i <= b; i++) {
Answer:
#include <stdio.h> void testscores(int student, int score) { float a; for (int i = 1; i <= student; i++) { float b = 0; fo
Answer:
#include <stdio.h> void Even_Odd_Numbers(int num) { int a; if (num < 0) { printf("Negative numbers are not allow
Answer:
#include <stdio.h> void Sum_Even_Odd_Numbers(int num) { int a, sum1 = 0, sum2 = 0; for (int i = 0; i < num; i++) {
Students are advised to fill the manual and submit it before the upcoming lab. Kindly rename the file as
‘MCT-242L_CP1_2022_LM10_XX’, where XX is your roll number. After completing the manual, turn it in Google Classroom.