UVA10035:

Primary Arithmetic

#include <iostream>;

using namespace std;

int main(){
	int n1, n2;
	
	

	while(cin >> n1 >> n2){
		if(n1 == 0 && n2 == 0){
			break;
		}

		int counter = 0;
		int carry = 0; 
		int sum = 0; 


		while(n1 > 0 || n2 > 0){

		
			sum = carry + (n1 % 10) + (n2 % 10);

			if(sum >= 10){
				counter++;
			}

			carry = sum/10;

			n1 /= 10;
			n2 /= 10;

	}

		if(counter == 1){
			cout << counter << " carry operation." << endl; 

		} else if(counter > 1){
			
			cout << counter << " carry operations." << endl; 

		} else {
			
			cout << "No carry operation." << endl;

		}


	}	


	return 0;
}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel