Professional Documents
Culture Documents
Looping Constructs Mendiola - Assessment
Looping Constructs Mendiola - Assessment
Looping Constructs Mendiola - Assessment
Situation: You are tasked with writing a program that counts and prints all even numbers between 1 and
20 using a loop. Use a for loop to iterate through the numbers and print only the even ones.
#include <stdio.h>
int main() {
printf("%d\n", even);
return 0;
Situation: Your task is to create a program that calculates the factorial of a given number. Use a while
loop to compute the factorial of a user-input integer.
#include <stdio.h>
int main() {
printf("Enter a number:");
scanf("%d",&number);
f=f*i;
i++;
return 0;
Situation: Write a program to display the following pattern using nested for loops.
1
22
333
4444
55555
#include <stdio.h>
int main() {
Name: Adriel D. Mendiola COMP 002 – Computer Programming 1
Year&Section: BSIT 1-4 Using Looping Constructs
int rows = 5;
for (int i=1; i <= rows; i++ ){
for(int j = 1; j<=i;j++){
printf("%d", i);
}
printf("\n");
}
return 0 ;
}
return 0;
}
Situation: You are developing a program that converts temperatures from Celsius to Fahrenheit. Allow
the user to convert multiple temperatures until they choose to exit.
#include <stdio.h>
int main() {
float Fahrenheit,Celsius;
char choice;
do{
scanf("%f", &Celsius);
return 0;