Escolar Documentos
Profissional Documentos
Cultura Documentos
1
If (a > b)
m = k;
else
m = n;
What will be the equivalent conditional statement (ternary expression) of the above
code?
Attempted answer: Just assign the value to a variable of desired date type
Correct answer:
By using instruction in this format (<desired data type>) <variable name>
4
#include <stdio.h>
#include
int main()
{
int i = 1;
switch(i)
{
case 1 : printf("%d",i);
case 2 : printf("%d",i+1);
case 3 : printf("%d",i+2);
case 4 : printf("%d",i+3);
}
}
What will be the output of the mentioned code?
Attempted answer: 1
Attempted answer: %f
8
#include <stdio.h>
int main()
{
int i, k;
for (i = 1; i <= 3; i++ )
{
for (k = 1; k <= i; k++)
printf("i");
printf("\n");
}
}
What will be the output of the following code?
Attempted answer:
123
12
Correct answer:
i
ii
iii
9
#include <stdio.h>
int main()
{
int x = 5, y = 10;
y = ++x - y + x++;
printf("%d %d", x, y);
}
What will be the output ?
Attempted answer:
7 3
Correct answer:
7 2
10
#include
int main()
{
int n = 487, d, e = 0;
while(n > 0)
{
e = e + n;
n = n / 10;
}
printf("%d", e);
}
Predict the output of the given program.
Attempted answer: Switch case does not allow comparing high or low.
12
#include <stdio.h>
int main()
{
int n = 423, d, e = 0;
while(n > 0)
{
d = n % 10;
e = e + d;
n = n / 10;
}
printf("%d", e);
}
What will be the output?
Attempted answer: 5
Correct answer: 9
Attempted answer: !
14
#include <stdio.h>
int main()
{
int x , y=1;
for (x=1; x>=0; x++)
{
y = y + 1;
if (y > 5)
break;
}
printf ("%d", x);
}
What is the output of the program?
Attempted answer: 2
Correct answer: 5