What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}101010101001234567890101010101I don't knowSubmit
Question
What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}101010101001234567890101010101I don't knowSubmit
Solution
The given code is a loop in C programming language that starts with i = 10 and increments i by 1 in each iteration until i is less than 20. In each iteration, it prints the remainder of i divided by 2 (i % 2).
Here is the step by step breakdown:
- When i = 10, i % 2 is 0, so it prints 0.
- When i = 11, i % 2 is 1, so it prints 1.
- When i = 12, i % 2 is 0, so it prints 0.
- When i = 13, i % 2 is 1, so it prints 1.
- When i = 14, i % 2 is 0, so it prints 0.
- When i = 15, i % 2 is 1, so it prints 1.
- When i = 16, i % 2 is 0, so it prints 0.
- When i = 17, i % 2 is 1, so it prints 1.
- When i = 18, i % 2 is 0, so it prints 0.
- When i = 19, i % 2 is 1, so it prints 1.
So, the output of the code will be 0101010101.
Similar Questions
What is the output for the following code?12345678910111213#include <stdio.h> int main() { int i = 1; while (i <= 10) { if (i % 5 == 0) { i++; continue; } printf("%d ", i); i++; } return 0; }
What is the output of the code given below?#include <stdio.h> void main() { int i; for (i = 5; i < 10; i++); printf("%d ", i);}Options5105 6 7 8 99
What is the output of int a = 10; printf("%d", a << 2);?
What is The Output of the following program? #include<stdio.h> void main() { int i = printf("00"); int i =printf("00"); printf("%d",i); } 0 00 002
What would be the output of the following program? #include <stdio.h> int main( ) { int j=1; while (j <= 255) { printf ( "%c %d\n ", j, j ); j++; } return 0; }
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.