URI Solution 1212 Primary Arithmetic - Solution in C, C++
URI Online Judge Solution | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1212
Problem Name: URI Problem 1212 Primary Arithmetic
Problem Number : URI Problem 1212 Primary Arithmetic Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus
URI 1212 solution in C language/ URI Primary arithmetic code in C:
#include <stdio.h> #include <string.h> long NumCarryAdd(long n1, long n2 ) { long a,b,c,t; c = 0; t = 0; while(1) { a=n1%10; b=n2%10; n1=n1/10; n2=n2/10; if((a+b+c)>=10) { t++; c=1; } else c = 0; if(n1==0 && n2==0)break; } return t; } int main() { long x, y, carry; while(1) { scanf("%ld %ld", &x,&y); if(x == 0 && y == 0) break; carry = NumCarryAdd(x, y); if(carry == 0) printf("No carry operation.\n"); else if(carry==1)printf("1 carry operation.\n"); else printf("%ld carry operations.\n", carry); } return 0; }
URI Solution 1212 Primary Arithmetic Code in CPP:
#include <iostream> using namespace std; int main(int argc, char const *argv[]) { long int a, b, _a, _b, c, carry, result; while (cin >> a >> b && (a || b)) { carry = c = 0; while (a != 0 || b != 0) { _a = a % 10; a = a / 10; _b = b % 10; b = b / 10; result = _a + _b + c; if (result >= 10){ c=1; carry += 1; } else c=0; } if (carry == 0){ cout << "No carry operation." << endl; } else if (carry == 1){ cout << carry << " carry operation." << endl; } else if (carry > 1){ cout << carry << " carry operations." << endl; } } return 0; }
Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list URI 1212 solution, URI Primary Arithmetic solution, URI 1212 Primary Arithmetic Solution, URI 1212 code in C, URI 1212 solution in C++
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks