0% found this document useful (0 votes)
30 views2 pages

How To Find The Bigger Number in C++

This C++ code defines a function that takes two strings representing numbers as input, compares the digits of the numbers from right to left to determine which number is larger, and returns the larger number or indicates if they are equal. It then demonstrates calling this function with user input numbers to output the larger of the two numbers.

Uploaded by

Richard Foster
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

How To Find The Bigger Number in C++

This C++ code defines a function that takes two strings representing numbers as input, compares the digits of the numbers from right to left to determine which number is larger, and returns the larger number or indicates if they are equal. It then demonstrates calling this function with user input numbers to output the larger of the two numbers.

Uploaded by

Richard Foster
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to find the bigger number in C++

#include <string>

#include <iostream>

#include <sstream>

using namespace std;

string groessere(string i1, string i2){

int lengthDif = 0;

string longer = "", smaller = "";

if(i1.length() > i2.length()){

lengthDif = i1.length() - i2.length();

longer = i1;

smaller = i2;

else{

lengthDif = i2.length() - i1.length();

longer = i2;

smaller = i1;

for(unsigned int i = 0; i < lengthDif; i++){

if(longer[i] > '0') return longer;

}
for(unsigned int i = 0; i < smaller.length(); i++){

int a = (i1[i1.length() - i -1] -'0');

int b = (i2[i2.length() - i -1] -'0');

cout << a << endl;

cout << b << endl;

if( a > b ) return i1;

else if(b > a) return i2;

return "Die Zahlen sind gleich";

int main() {

//erstens nutzereingabe

cout << "Insert the first number: " << endl;

//definieren der variablen

string erste, zweite;

cin >> erste;

cin >> zweite;

//vergleich der Zahlen

cout << "The bigger Number is:" << endl;

cout << groessere(erste, zweite);

You might also like