| | |
Can any1 tell me whatz wrong in this program...this does not show the output!!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
Hey can any1 figure out wat is wrong in this program...after i compiled it and executed the program ....I inputed the value of n...but after that it does not show the output...Can any1 help me plz..!!
The program which I wrote is below::
#include<iostream.h>
int sumofdigits(int n)
{
int sum=0, x;
while(n>0)
{
x=n%10;
sum+=x;
}
return sum;
}
void main()
{
int n, sum;
cout<<"Enter any number"<<endl;
cin>>n;
sum=sumofdigits(n);
cout<<"Sum of digits ="<<sum;
cout<<endl;
}
The program which I wrote is below::
#include<iostream.h>
int sumofdigits(int n)
{
int sum=0, x;
while(n>0)
{
x=n%10;
sum+=x;
}
return sum;
}
void main()
{
int n, sum;
cout<<"Enter any number"<<endl;
cin>>n;
sum=sumofdigits(n);
cout<<"Sum of digits ="<<sum;
cout<<endl;
}
>>>Extreme<<<
Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!
0
#2 Nov 29th, 2004
You forgot to update the loop counter.
while(n>0)
{
x=n%10;
sum+=x;
n/=10;
}•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!
0
#3 Nov 29th, 2004
![]() |
Similar Threads
- Could you tell me what is (are) wrong of my program? (Pascal and Delphi)
- While or For loop (C)
- Can anyone figure out what is wrong in my program? (C++)
- program does not seems to run to end. (C++)
- What is wrong with my program? (Assembly)
Other Threads in the C++ Forum
- Previous Thread: Size
- Next Thread: Problems with switch statement
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






