I'm having a lab practical and has C++ programs. For the question 'Program to find the sum of digits of an integer number' here is the given code on our record book:
But this doesn't seem to work and is giving the following errors
g++ -Wall -c "untitled.cpp" (in directory: C:\Users\Arjun\Desktop)
untitled.cpp: In function 'int main()':
untitled.cpp:14:31: error: expected primary-expression before '/' token
Compilation failed.
Please give the correct code for this program.
Code:
#include <iostream>
using namespace std;
int main()
{
int n,rem,s=0;
cout<<"Enter the digits :";
cin>>n;
while(n>0)
{
rem=n%10;
s=s+rem;
n=n/10;
}
cout<<"Sum of digits = "<<s<</n;
return 0;
}
g++ -Wall -c "untitled.cpp" (in directory: C:\Users\Arjun\Desktop)
untitled.cpp: In function 'int main()':
untitled.cpp:14:31: error: expected primary-expression before '/' token
Compilation failed.
Please give the correct code for this program.
Last edited: