help me in this program....
Write a program that prompt the user ti input an integer and then outputs the
numbers with digits reversed. for example, if the input is 12345 the output should be 54321. Your program should find the summation of all digits, for previous example the summation will be 15.
this is my solution.. but. I think.. its not correct..
[CODE=cpp]
#include <iostream>
#include<fstrea m>
using namespace std;
int main()
{
int num,digit,sum=0 ;
ifstream infile;
ofstream outfile;
infile.open("in Data.txt");
outfile.open("o utData.txt");
infile>>num;
outfile<<"Numbe r: "<<num<<end l;
while (num>0)
{
digit=num%10;
num=num/10;
if(digit>0)
num=num%10;
num=num/10;
sum++;
}
outfile<<"Numbe r in reverse Order:"<<num<<e ndl;
outfile<<"Summa tion of Digits: "<<sum<<end l;
infile.close();
outfile.close() ;
return 0;
}
[/CODE]
can any body help me???
Write a program that prompt the user ti input an integer and then outputs the
numbers with digits reversed. for example, if the input is 12345 the output should be 54321. Your program should find the summation of all digits, for previous example the summation will be 15.
this is my solution.. but. I think.. its not correct..
[CODE=cpp]
#include <iostream>
#include<fstrea m>
using namespace std;
int main()
{
int num,digit,sum=0 ;
ifstream infile;
ofstream outfile;
infile.open("in Data.txt");
outfile.open("o utData.txt");
infile>>num;
outfile<<"Numbe r: "<<num<<end l;
while (num>0)
{
digit=num%10;
num=num/10;
if(digit>0)
num=num%10;
num=num/10;
sum++;
}
outfile<<"Numbe r in reverse Order:"<<num<<e ndl;
outfile<<"Summa tion of Digits: "<<sum<<end l;
infile.close();
outfile.close() ;
return 0;
}
[/CODE]
can any body help me???
Comment