Skip to content

Instantly share code, notes, and snippets.

@MuhammadJahidHasan
Created November 23, 2017 14:03
Show Gist options
  • Save MuhammadJahidHasan/00491abbfed5694cb31dd8f6ec9a2b5c to your computer and use it in GitHub Desktop.
Save MuhammadJahidHasan/00491abbfed5694cb31dd8f6ec9a2b5c to your computer and use it in GitHub Desktop.
How to convert string to integer and integer to string in c++
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a,b,c,val,co=0;
string s,revs;
cin>>a>>b>>c;
for(int i=min(a,b);i<=max(a,b);i++){
s= to_string(i);
reverse(s.begin(), s.end());
val=atoi(s.c_str());
if(abs(i-val)%c==0)
co++;
}
cout<<co;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment