Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a string variable with a series of intenger digits. Each digit is

ID: 3569513 • Letter: Y

Question

You are given a string variable with a series of intenger digits. Each digit is one position long, meaning you only consider the digits 0 thru 9, so"11" is not eleven but two single digits of one and one. Write a program in pseudo code to display a count of the number of 'even' digits, and count of the number of 'odd' digits. Also provide a sum of the 'even' digits and a sum of the 'odd' digits.

Example input

19623598233256

Example output

The number of even numbers in the string is XXX

The number of odd numbers in the string is XXX

The sum of the even numbers in the string is XXX

The sum of the odd numbers in the string is XXX

Explanation / Answer

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,i,sumeven=0,sumodd=0,even=0,odd=0;
cout<<"Enter value of n:";
cin>>n;

for(i=1;i<=n;++i)
{
if(i%2==0)
even++;
sumeven+=i;
else
odd+;
sumodd+=i;
}
cout<<" Sum of even Numbers is "<<sumeven;
cout<<" count of even Numbers is "<<even;
cout<<" SUm of odd Numbers is "<<sumodd;
cout<<" count of odd Numbers is "<<odd;
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote