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

Write a program which: Asks the user to enter a positive integer greater than 0

ID: 3808860 • Letter: W

Question

Write a program which:

Asks the user to enter a positive integer greater than 0

Validates that the entry is a positive integer

Outputs the digits in reverse order with a space separating the digits

Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even)

If there are no even digits, the an appropriate message should be displayed: There are no even digits

Outputs the odd digits not in reverse order with a space separating the digits

If there are no odd digits, the an appropriate message should be displayed: There are no odd digits

Allows user is to repeat/continue the program as many times as he/she wants

Keeps a record in a txt file named outDataFile.txt with the history of all numbers entered and the associated results, in the following format:

the original number is 1234
the number reversed 4 3 2 1
the even digits are 2 4
the odd digits are 1 3
-----------------
the original number is 135
the number reversed 5 3 1
There are no even digits
the odd digits are 1 3 5
-----------------
the original number is 862
the number reversed 2 6 8
the even digits are 8 6 2
There are no odd digits
-----------------

Explanation / Answer

#include <iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int main()
{
char s[1000000];
int k=0,l=0;
cout<<"enter the no. greater than 0"<<endl;
gets(s);
int n=strlen(s);
cout<<"the reversed digits";
for(int i=n-1;i>=0;i--)
{
cout<<s[i]<<" ";

}
cout<<endl;
for(int j=0;j<n;j++)

{
if(s[j]%2==0)
k++;
else
l++;

}
if (k==0)
cout<<"there are no even numbers";
else
{

cout<<"the even digits are ";
for(int j=0;j<n;j++)

{
if(s[j]%2==0)
cout<<s[j]<<" ";
}
cout<<endl;
}
if (l==0)
cout<<"there are no odd numbers ";
else
{
cout<<"the odd digits are ";
for(int j=0;j<n;j++)
{
if(s[j]%2!=0)
cout<<s[j]<<" ";
}

}
}

output

enter the no. greater than 0
12345
the reversed digits5 4 3 2 1
the even digits are 2 4
the odd digits are 1 3 5

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