Professional Documents
Culture Documents
Overview
The following code represents three different possibilities to find a bigger number between
two numbers in C++. As the input are strings, the numbers are not restricted to the int or
long data type size.
Code in C++11
One
string>
#include <
#include < iostream>
#include < sstream>
0
int lengthDif = ;
string longer = " ", smaller = "";
if( a > b )
r eturn i1;
else if(b > a) return i2;
}
return "Die Zahlen sind gleich";
}
int main() {
//erstens nutzereingabe
cout << "Insert the two numbers: " << endl;
Two
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
int result = 0;
result += a * pow(10,(s.length()-1-i));
}
return result;
}
int main() {
//erstens nutzereingabe
cout << "Insert the two numbers: " << endl;
Three
string>
#include <
#include < iostream>
#include < sstream>
string final;
for(char c : s){
int a = c - '0';
if(a != 0 &
& !works){
works = true;
}
if(works){
final += c;
}
}
int result = 0;
stringstream(final) >> result;
return result;
}
int main() {
//erstens nutzereingabe
cout << "Insert the two numbers: " << endl;