











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lab exercise focuses on the practical application of loops in computer programming. Students are tasked with implementing various tasks using both 'for' and 'while' loops, demonstrating their understanding of loop syntax, conditional execution, and iterative processes. The lab includes tasks such as calculating simple interest, generating multiplication tables, printing ascii characters, and creating patterns of asterisks. It provides a hands-on approach to learning fundamental programming concepts.
Typology: Schemes and Mind Maps
1 / 19
This page cannot be seen from the preview
Don't miss anything!












ASSESSMENT In-Lab Performance: / Post-Lab:
Total: / Instructor’s remarks: Lab # 03 Using Loops to Print Number
Sequences and Patterns
#include<stdio.h> int main() { int p, n; float r, SI; int i; for (i=1; i<=5; i++) { printf("Enter the value of p, n and r: "); scanf("%d %d %f", &p, &n, &r); SI = (pnr)/100; printf("The Simple Interest for the given values of p,n and r is: %.3f\n", SI); } return 0; }
#include<stdio.h> int main()
#include <stdio.h> int main() { int x,y; printf("The Table of="); scanf("%d",&x); y=1; while(y<=10) { printf("%d%d=%d\n",x,y,xy); y++; } return 0; }
#include<stdio.h> int main() { for (int i=0; i<=255; i++){ printf("%d = %c\n",i,i); } return 0; }
#include <stdio.h> int main() { int red, green, blue; for (red = 1; red <= 3; red++) { for (green = 1; green <= 3; green++) { for (blue = 1; blue <= 3; blue++) { printf("%d, %d, %d\n", red, green, blue); } } } return 0; }
#include<stdio.h> int main() { int red=1; while(red<=3){ int green=1; while(green<=3){ int blue=1; while(blue<=3){ printf("%d,%d,%d\n",red,green,blue); blue++; } green++; } red++; } return 0; }
#include <stdio.h> int main() { int value=1,sum=0; while (value <= 10) { sum = sum + value; value++; } printf("Sum of first 10 natural numbers = %d",sum); return 0; }
#include<stdio.h> int main() { int n, i, pink = 0; printf("Enter a positive integer "); scanf("%d",&n); for(i=2; i<=n/2; ++i) { if(n%i==0){ pink=1; break; } } if (pink==0){ printf("%d is a prime number.",n); } else{ printf("%d is not a prime number.",n); } return 0; }
for(i=1; i<=digit; i++) { factorial = factorial*i; } printf("Factorial of %d is: %d", digit, factorial); return 0; }
#include<stdio.h> int main() { int i,digit,factorial=1; printf("Enter an integer"); scanf("%d",&digit); i=1; while(i<=digit) { factorial=factorial*i; i++; } printf("Factorial of %d is %d",digit,factorial); return 0; }
#include <stdio.h> int main() { int overtime, hours; float rate = 1200; float salary; printf("Enter the number of overtime hours: "); scanf("%d", &overtime); for (int i = 1; i <= 10; i++) { hours = overtime * i; salary = rate * hours; printf("Overtime salary of Employee %d is: Rs. %.2f\n", i, salary); } return 0; }
#include<stdio.h> int main() { int overtime_hours, i=1; float overtime_pay; while(i<=10) { printf("Enter the overtime hours of employee %d: ",i); scanf("%d",&overtime_hours); overtime_pay=overtime_hours*1200;