Logic operators quiz, While loop questions & Switch questions (C for Everyone: Programming Fundamentals - Week 3 Coursera)
#include <stdio.h> #include <stdlib.h> int main(void) { int a = 0, b = 1, c = 2; If (a < b) printf (" TRUE\n"); else printf(" FALSE\n"); If (a < b - c) printf (" TRUE\n"); else printf(" FALSE\n"); If (b < c - 1) printf (" TRUE\n"); else printf(" FALSE\n"); If (!c) printf (" TRUE\n"); else printf(" FALSE\n"); return 0; } What does the program print as a first line?
True
while (i < 5){ i = i - 1; printf(" i = %d", i); } If i starts off as 2 (assume int i = 2 declared at the beginning of the code) then...
printf will print continuously
while (i < 5){ i = i - 1; printf(" i = %d", i); } If i starts off as 15 (assume int i = 15 declared at the beginning of the code), printf will print ...
will not print
If i starts out as 2 the printf will print
case 2 case 3
while (i < 5){ i = i - 1; printf(" i = %d", i); } If i starts off as 2 (assume int i = 2 declared at the beginning of the code) and the loop statement was i = i +1; printf will print ...
i = 3 i = 4 i = 5
#include <stdio.h> #include <stdlib.h> int main(void) { int a = 0, b = 1, c = 2; If (a < b) printf (" TRUE\n"); else printf(" FALSE\n"); If (a < b - c) printf (" TRUE\n"); else printf(" FALSE\n"); If (b < c - 1) printf (" TRUE\n"); else printf(" FALSE\n"); If (!c) printf (" TRUE\n"); else printf(" FALSE\n"); return 0; } What does the program print as a fourth line?
F
#include <stdio.h> #include <stdlib.h> int main(void) { int a = 0, b = 1, c = 2; If (a < b) printf (" TRUE\n"); else printf(" FALSE\n"); If (a < b - c) printf (" TRUE\n"); else printf(" FALSE\n"); If (b < c - 1) printf (" TRUE\n"); else printf(" FALSE\n"); If (!c) printf (" TRUE\n"); else printf(" FALSE\n"); return 0; } What does the program print as a second line?
F
#include <stdio.h> #include <stdlib.h> int main(void) { int a = 0, b = 1, c = 2; If (a < b) printf (" TRUE\n"); else printf(" FALSE\n"); If (a < b - c) printf (" TRUE\n"); else printf(" FALSE\n"); If (b < c - 1) printf (" TRUE\n"); else printf(" FALSE\n"); If (!c) printf (" TRUE\n"); else printf(" FALSE\n"); return 0; } What does the program print as a third line?
F
switch(i){ case 1: printf("case 1 \n"); break; case 2: printf("case 2 \n"); case 3: printf("case 3 \n");break; default: printf("default case \n"); }; Use the code above for all of the questions. If i starts off as 1 then printf will print
case 1
If i starts out as 15 the printf will print
default case