Answer to Question #258731 in C++ for lani

Question #258731

Program

Create a program that will accept a character array input with a maximum array size of 30 and will check if the input contains a number.


Sample Input #1

2sHO4p

Sample Output #1

Numbers Exist:24


Sample Input #2

love

Sample Output #2

No Number


Sample Input #3

g00d morn1ng (space between characters)

Sample Output #3

Number Exist:001


1
Expert's answer
2021-10-30T00:39:31-0400
#include <iostream>
using namespace std;
void splitNum(string no){
string alp,num;
for(int i=0;i<no.length();i++){
    if (isdigit(no[i]))
        num.push_back(no[i]);
        else if ((no[i] >='A' && no[i]<='Z')||(no[i]>='a' && no[i]<='z'))
        alp.push_back(no[i]);
}
cout<<"Number Exist:"<<num<<endl;
}
int main()
{
string no;
cout<<"enter input"<<endl;
cin>>no;
splitNum(no);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS