- 3
What is the output plzz explain too
Int tot=0,i; for(int i=0; i<10;i++) { tot=tot+1; }printf("%d", tot);
13 odpowiedzi
+ 2
At every iteration it is increasing the value of tot by 1 and the ending point of the condition is 9,so the answer of 10. If you don't understand please complete the course to know about it
+ 1
#include <stdio.h>
int main() {
//What is the output plzz explain too
int tot=0,i;
for(i=0; i<10;i++)
{
tot=tot+1;
}printf("%d", tot);
return 0;
}
//This is the correct code
+ 1
Code:
#include <stdio.h>
int main()
{
int tot = 0 , i ;
for(i=0; i<10; i++)
{
tot = tot + 1;
}printf("%d", tot);
return 0;
}
In the code a for loop is used . The loop would iterate until the condition ( i < 10) is false .
Initially tot = 0 , for each iteration one value is added to 'tot'
( tot = tot + 1 )
From i = 0 to i<10 i.e 'i' value is from 0 to 9 (10 values)
The loop iterates 10 times and the number of times 1 is added to the variable 'tot' is 10 .
So the value of the variable 'tot' is 10.
+ 1
For value of i from 0 to 9 that is 10 times the loop will work and value of total will be 10
0
Atul then how update the value of tot??
0
Tot's value is always updated in every iteration
0
I didn't get but thanks
0
What doubt you have pls ask?
0
Already asking read above
0
I must suggest you to know about the working of loops before solving about this
0
Output is the sum of all number untill 10 (excluding 10)
In each iteration i is increase by 1 and add to total.
0
Here int I is declared twice beside all the error coming to the core answer is 10
0
Output must be 10. Through each iteration total is added 1 to the total.