4. What will be the output of the
program ? int main() { int a[3] =
{10,12,14}; a[1]=20; int i=0; while(i<3) {
printf("%d", a[i]); i++; } }
Answers
Answered by
4
Answer:
output:⬇️
10 20 14
Explanation:
a[i] is (i+1) element. So a[1] changes the second element.
Answered by
0
Concept:
While loop is also known as a loop that has been pre-tested. A while loop, in general, allows a section of code to be run many times depending on a boolean state. It can be thought of as a repeated if statement.
Given:
#include <stdio.h>
int main()
{ int a[3] = {10,12,14};
a[1]=20;
int i=0;
while(i<3)
{
printf("%d ", a[i]); i++; }
}
Find:
Find the output.
Solution:
Here a is a one-dimensional array having three values {10, 12, 14}
a[1] = 20 will change the value of the item at index 1 to 20.
∴ The updated array would be (10, 20, 14)
while(i<3) will execute the following code 3 times and print the value of each item of the array.
Output: 10, 20, 14
∴ The output will be 10, 20, 14.
Similar questions