0% found this document useful (0 votes)
22 views2 pages

Lab5 - Structure Programming Model Answer

The document contains programming exercises for a course at Alalamein University, specifically for the Faculty of Basic Science. It includes model answers for three tasks: printing numbers from 1 to 10 using a for loop, counting down from 10 to 0 using a while loop, and printing numbers from 1 to a user-defined number. Each task is accompanied by sample code in C programming language.

Uploaded by

mb1989301
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)
22 views2 pages

Lab5 - Structure Programming Model Answer

The document contains programming exercises for a course at Alalamein University, specifically for the Faculty of Basic Science. It includes model answers for three tasks: printing numbers from 1 to 10 using a for loop, counting down from 10 to 0 using a while loop, and printing numbers from 1 to a user-defined number. Each task is accompanied by sample code in C programming language.

Uploaded by

mb1989301
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

Alalamein University Structure

Faculty of Basic Programming


science Course Code: CSE014

Lab 5
Model Answer
1) Write a program using (For) Loop that prints numbers from 1 to 10.

int main() {
printf("Numbers from 1 to 10 using for loop:\n");

for (int i = 1; i <= 10; i++) {


printf("%d\n", i);
}

return 0;
}

2) Write a program using (while) Loop that prints a count down from 10 to 0.

int main() {
int num = 10;

printf("Counting down from 10 to 1 using while


loop: \n");

while (num >= 0) {


printf("%d\n", num);
num--;
}

return 0;
}

1
Alalamein University Structure
Faculty of Basic Programming
science Course Code: CSE014

3) Write a program that takes a number from the user then prints numbers from 1 to
this number.

int main() {
int end_number;

printf("Please enter a number to print from 1 to (Number): 3 \n");


scanf("%d", &end_number);

for(int i = 1; i <= end_number; i++) {


printf("%d\n", i);
}

return 0;
}

You might also like