Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What are the outputs of the following C statements? For some, you may need to in

ID: 3607647 • Letter: W

Question

What are the outputs of the following C statements? For some, you may need to input

(a) i = 1;

       while (i <= 64)

       {

          printf("%d ", i);

          i *= 2;

       }

(b) i = 9384;

       do {

          printf("%d ", i);

          i /= 10;

       } while (i > 0);

(c) int i;

       for (i = 10; i >= 1; i /= 2)

          printf("%d ", i++);

(d) int a[3] = {1, 2, 3};

       int b[3];

      

       b = a; // What is the effect of this statement? If an error,

              // explain why.

(f) int index = 1;

       while (index++ < 4)

       {

          printf("Value of expression is: %d ", 2 * index + 2);

       }

(g) #include

       #define FORMAT   "%s! C is cool! "

  

       int main( )

       {

          printf(FORMAT, FORMAT);

          return ;

       }

(h) int x = 0;

       while (++x < 3)

          printf("%4d", x);

(i) #include

       int main( )

       {

          int i = 0;

          while (++i < 4)

             printf("Hi! ");

         

          do {

             printf("Bye! ");

          } while (i++ < 7);

          puts(" ");

          return 0;

       }

   

(j) char ch;

       for (ch = 'a'; ch <= 'd'; ch++)

          printf("The ASCII value for %c is %d ", ch, ch);

(k) #include

       int main( )

      {

          int i = 0;

          while (i < 3)

          {

             switch(i++)

             {

                case 0 : printf("cat ");

                case 1 : printf("hat ");

                case 2 : printf("rat ");

                default: printf("Oh no!);

             }

             puts(" ");

          }

         

          return 0;

       }

(l) #include

       int fun1(int n);

       int main( )

       {

          int num;

          printf("Enter a positive integer: ");

          scanf("%d", &num);

          printf("Value returned = %d ", fun1(num));

          return 0;

       }

       int fun1(int n)

       {

          if (n != 0)

             return n + fun1(n-1);

          else

             return n;

       }

Explanation / Answer

Question a)
Anser:
1 2 4 8 16 32 64
Question b)
Anser:
9384 938 93 9
Question c)
Anser:
Infinity loop. loop will never end
Question d)
Anser:
error: assignment to expression with array type

Question f)
Anser:
Value of expression is: 6
Value of expression is: 8
Value of expression is: 10
Question g)
Anser:
%s! C is cool!
! C is cool!
Question h)
Anser:
1 2
Question i)
Anser:
Infinity loop. loop will never end
Question j)
Anser:
The ASCII value for a is 97
The ASCII value for b is 98
The ASCII value for c is 99
The ASCII value for d is 100
Question k)
Anser:
cat hat rat Oh no!

hat rat Oh no!

rat Oh no!
Question l)
Anser:
Enter a positive integer: 5
Value returned = 15

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote