Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Homework C Lecture 3

The document outlines corrections for programming errors in C code, including syntax issues in for loops and switch statements. It also presents a pattern printing program based on user input and a program to find the smallest integer from a list. Additionally, it includes examples of various for loop structures.

Uploaded by

Lý Khải Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Homework C Lecture 3

The document outlines corrections for programming errors in C code, including syntax issues in for loops and switch statements. It also presents a pattern printing program based on user input and a program to find the smallest integer from a list. Additionally, it includes examples of various for loop structures.

Uploaded by

Lý Khải Minh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

HOMEWORK C LECTURE 3 ½

Question 1:
a>
Errors and Corrections:
1. The loop keyword For should be lowercase as for.
2. The components of the for loop should use semicolons (;) instead of commas (,).
Corrected Code:
for (x = 100; x >= 1; x--)
printf("%d\n", x);

b>
Errors and Corrections:
1. Missing break statements after each case, which are needed to prevent fall-through to the next case.
2. Optionally, you might include a default case to handle unexpected values.
Corrected Code:
switch (value % 2) {
case 0:
printf("Even integer\n");
break;
case 1:
printf("Odd integer\n");
break;
default:
printf("Unexpected value\n");
}

Question 2:
a> b> c> d> e>
2 5 3 1 12
4 12 6 9
6 19 9 6
8 12 3
10 15
12

Question 3:
a> for (int i = 1; i <= 7; i++) { c> for (int i = 20; i >= -10; i -= 6) {
printf("%d", i); printf("%d", i);
if (i < 7) printf(", "); if (i > -10) printf(", ");
} }
b> for (int i = 3; i <= 23; i += 5) { d> for (int i = 19; i <= 51; i += 8) {
printf("%d", i); printf("%d", i);
if (i < 23) printf(", "); if (i < 51) printf(", ");
} }
Question 4:

This program is designed to take two integers as input and print a pattern of @ symbols based on the
provided values:

1. The first integer (x) determines the number of @ symbols printed in each row.
2. The second integer (y) determines the number of rows in the pattern.

Question 5:
#include <stdio.h>

int main() {
int n, num, smallest;

printf("Enter the number of integers to be processed: ");


scanf("%d", &n);

printf("Enter an integer: ");


scanf("%d", &smallest);

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


printf("Enter next integer: ");
scanf("%d", &num);

if (num < smallest) {


smallest = num;
}
}

printf("\nThe smallest integer is: %d\n", smallest);

return 0;
}

You might also like