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
#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;
}
Comments
Leave a comment