// Q(3) - (25 marks)
// 1- number of digits of positive long integer number
// 2- sum of even digits entered by the user
// Sample Input/Output:
// Enter a positive long number: 372946
// Number of digits = 6
// Sum of even digits = 12
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int x;
int n=0;
cout<<" Enter a positive long number:";
cin>>x;
while (x)
{
x=x/10;
n++;
}
cout<<" Number of digits ="<<n<<endl;
for (int j=5; j>0; --j)
j=j+n;
while (j)
{
--j;
if (x/j%2==0)
++s;
}
cout<<"sum of even digits ="<<n;
system("PAUSE");
return 0;
}
lines 29-30, you're likely to loop indefinitely here, perhaps you meant to use 2 variables instead of 1?
line 32, j is now out of scope and undefined
line 36 s is undefined
line 38, since you've made no further changes to n since line 27, the veracity of this statement is dubious
#include <iostream>
usingnamespace std;
int main()
{
int x, evenSum=0;
int n=0;
x=123456;
while (x)
{
if((x%10)%2==0) evenSum+= (x%10);
x=x/10;
n++;
}
cout<<" Number of digits ="<<n<<endl;
cout<<"sum of even digits ="<<evenSum;
return 0;
}