Question: Question 3. For each case, write a for statement that prints the sequences of its values: a) 24, 12, 6, 3 b) 3, 8, 13,
Question 3.
For each case, write a for statement that prints the sequences of its values:
a) 24, 12, 6, 3
b) 3, 8, 13, 18, 23
c) 20, 14, 8, 2, -4, -10
d) 3, 6, 9, 12, 15, 18
Question 4.
What does the following program print?
#include
int main(void)
{
unsigned int x = 1;
unsigned int total = 0;
unsigned int y;
whil (x <= 10) {
y= x * x;
printf("%d ", y);
total += y;
++x;
} //end while
printf("Total is %d ", total);
} //end main
Question 5.
What does the following program print? How many inputs will be asked inside the loop from the user before exiting from the loop?
float price;
float total = 0;
int counter = 5;
do {
printf("Enter the iten price: ");
scanf("%f", &price);
total += price;
} while (counter --);
printf("Total = %8.2f", total);
Question 6.
What does the following program print? By assuming that the user enters 4 for x and 6 for y, show the output of this program.
#include
int main(void)
{
unsigned int x;
unsigned int y;
//prompt user for input
printf("%s", "Enter two unsigned integers in the range 1-20:");
scanf("%u%u", &x, &y); //read values for x and y
for (unsigned int i = 1; i <= y; ++i) { //count from 1 to y
for (unsigned int j = 1; j <= x; ++j) { //count from 1 to x
printf("%s", "@");
}
puts (""); //begin new line
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
