there is a string "1234567890"
I want to sum up the 1st , 3rd, 5th ,7th and 9th digits
how can I do it?
Hope This Would Help. :)
#include<iostream.h>
int str[] = {1,2,3,4,5,6,7,8,9,0};
int i,sum=0,_sum=0,*x;
int main()
{
x = str;
for(i=0;i<10;i++)
{
cout << " " << *x;
if(*x%2==1)
sum=sum+ *x;
else
_sum=_sum+ *x;
x++;
}
cout << "\n\n SUM for Odd numbers:" << sum;
cout << "\n\n SUM for Even numbers:" << _sum;
return 0;
}
Last edited on