- 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);

10th Jun 2021, 6:43 AM
Ansari Afzal
Ansari Afzal - avatar
13 Réponses
+ 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
10th Jun 2021, 7:03 AM
Atul [Inactive]
+ 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
10th Jun 2021, 7:02 AM
Atul [Inactive]
+ 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.
11th Jun 2021, 6:04 AM
GAYATHRI KOLLURI
GAYATHRI KOLLURI - avatar
+ 1
For value of i from 0 to 9 that is 10 times the loop will work and value of total will be 10
11th Jun 2021, 6:06 AM
Ravi
0
Atul then how update the value of tot??
10th Jun 2021, 3:39 PM
Ansari Afzal
Ansari Afzal - avatar
0
Tot's value is always updated in every iteration
10th Jun 2021, 3:52 PM
Atul [Inactive]
0
I didn't get but thanks
10th Jun 2021, 4:01 PM
Ansari Afzal
Ansari Afzal - avatar
0
What doubt you have pls ask?
10th Jun 2021, 4:08 PM
Atul [Inactive]
0
Already asking read above
10th Jun 2021, 4:56 PM
Ansari Afzal
Ansari Afzal - avatar
0
I must suggest you to know about the working of loops before solving about this
10th Jun 2021, 5:33 PM
Atul [Inactive]
0
Output is the sum of all number untill 10 (excluding 10) In each iteration i is increase by 1 and add to total.
11th Jun 2021, 12:27 AM
Thisal Rasindu
Thisal Rasindu - avatar
0
Here int I is declared twice beside all the error coming to the core answer is 10
11th Jun 2021, 11:12 PM
Dharmi Sri
Dharmi Sri - avatar
0
Output must be 10. Through each iteration total is added 1 to the total.
11th Jun 2021, 11:30 PM
Thisal Rasindu
Thisal Rasindu - avatar