Oct 9, 2009 at 2:11pm UTC
this is the task: Given two positive integers m and n. Determine the number m n last digit sum. Sharing the figure should be quantified.
the result is worng and i cant find mistake. When i use "/"everything is ok but with out quant its wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
using namespace std;
int main ()
{
int m,n,k,j=0,sum2=0,sum,sum1=0;
cout<<"ievadiet skaitli M: \n" ;
cin>>m;
cout<<"ievadiet skaitli N: \n" ;
cin >>n;
for (int i=0; i<=n; i++)
{
sum=m%10;
sum1=sum1+sum;
do
{
m=m-10;
j++;
m=j;
}
while (m>=10);
//m=m/10;
}
cout<<sum1<<endl;
system("pause" );
return 0;
}
Last edited on Oct 9, 2009 at 3:08pm UTC
Oct 9, 2009 at 2:45pm UTC
Huh?
Are you saying you want to calculate the sum of the last 'n' digits of 'm'?
Oct 9, 2009 at 2:53pm UTC
yes.
for example if i enter m=12345 and n=3 the he count 5+4+3
Last edited on Oct 9, 2009 at 2:54pm UTC