Question
What are the outputs of the following C statements? For some, you may need to input (a) i = 1; while (i 0); (c) int
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;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started