I wrote the below code to find the sum of all digits in C, and when I compiled and ran it, it was successful. But, only later I realized that i had not entered any value for the variable 'n' in the for loop's condition. I'm confused on how this program works, even when there is no value assigned to the condition variable. I would like to be clarified of the same.
#include<stdio.h>
void main()
{
int no,a,b,n,sum=0;
printf("Enter the number to be added");
scanf("%d",&no);
for(int i=0;i<n;i++)
{
a=no%10;
b=no/10;
sum=a+sum;
no=b;
}
printf("The sum is %d",sum);
}
nisn't initialized.