60 475
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #33848 in C++ for amit kumar

Question #33848
how can i check that a string contains integer or not in c language ? please write the full program
Expert's answer
#include <stdio.h>
#include <iostream>
#include <string>


using namespace std;


bool contains(string &s)
{
int i = 0;
while (s[i] != '')
{
if (s[i] == '1' ||
s[i] == '2' ||
s[i] == '3' ||
s[i] == '4' ||
s[i] == '5' ||
s[i] == '6' ||
s[i] == '7' ||
s[i] == '8' ||
s[i] == '9' ||
s[i] == '0')
++i;
else return false;
}
return true;
}


int main()
{
cout << "Enter string: ";
string str;
cin >> str;
cout << ((contains(str) == true) ? "Your string is an integer" : "Your string is not an integer");
cin.get();
cin.get();
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions