We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Because if there would be no space then it would read as 1 variable, f.e. you want to input 1 2 and 7. If you wont use space you'll get 127 as one number (int a = 127). Another solution to this problem would be seperating numbers with new line (pressing enter for each number individualy), but well, with spaces it is easier to show "starting values for tests"

## Input and Output

You are viewing a single comment's thread. Return to all comments →

Because if there would be no space then it would read as 1 variable, f.e. you want to input 1 2 and 7. If you wont use space you'll get 127 as one number (int a = 127). Another solution to this problem would be seperating numbers with new line (pressing enter for each number individualy), but well, with spaces it is easier to show "starting values for tests"

int main() { int n,sum=0,rem; cout<<"\n Enter a no."; cin>>n; while(n>0) { rem=n%10; sum=sum+rem; n=n/10; } cout<<"sum is="< return 0; }