Programming and Problem Solving
CSE · Quiz · Fall 26
Paper 5 of 6Section RE_D · Batch 66Switch
Section RE_D · Batch 66 · shared by MAHMUDUL HASAN
Paper 5 of 6Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Quiz-1
Course: CSE113: Programming and problem solving
Section: 71_1
1. Find the errors and write the correct version 5
#include <stdio.h>
int main() {
float x = 10.0;
int y = 20.5;
char z = "A";
printf("The value of x is %d\n", x);
printf("The value of y is %lf\n", y);
printf("The value of z is %f\n", z);
for (int i = 0,I =< 5, i++) {
sum += i;
}
Printf('Sum is : ');
Printf("%d",sum");
return 0
}
2. Find the output of the following code
#include <stdio.h>
int main()
{
int a = -10, b = 20;
if(a > 0 && b < 0)
a++;
else if(a < 0 && b < 0)
a--;
else if(a < 0 && b > 0)
b--;
else
b--;
printf("%d\n",a + b);
return 0;
}
3. Explain the differences between the for, while, and do-while loops in C. Provide an example for each. Convert the following for loop into a do-while loop using C programming. 6
#include <stdio.h>
int main() {
int i, num, sum = 0;
for (i = 1; i <= 5; i++) {
printf("Enter number %d: ", i);
scanf("%d", &num);
sum = sum + num;
}
printf("Sum of 5 numbers = %d", sum);
return 0;
}