Elementary school students arithmetic-java&c-statistics How many occurrences occur when two integers are added together

Source: Internet
Author: User

Problem Description: Calculates how many times the two integers need to be rounded up and processes multiple sets of data until they enter two 0.1.java
ImportJava.util.Scanner;/*** Statistics two number of times to add the amount of carry, the end of the flag input two 0 *@authorNEU-2015 **/ Public classDemo { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); intA = 0; intb = 0; intCount = 0;//count How many times the rounding        intresult = 0;//a+b The results of each number of digits         while(Input.hasnext ()) {a=Input.nextint (); b=Input.nextint (); Count= 0; Result= 0; if(A = = 0 && b = = 0) {//End FlagInput.close ();  Break; }                         while(A > 0 && B > 0) {result= (a%10 + b%10 + result) > 9? 1:0; Count+=result; A/= 10; b/= 10;    } System.out.println (count); //How many times the output is rounded        }    }}

2.c
#include <iostream>#include<stdio.h>using namespacestd;//no more than 9 digits are entered for the integer//@author NEU-2015intMain () {intA, B;  while(SCANF ("%d%d", &a, &b) = =2) {        if(!a &&!b)return 0; intc =0, ans =0;  for(inti =9; I >=0; i--) {C= (a%Ten+ b%Ten+ c) >9?1:0; Ans+=C; A/=Ten; b/=Ten; } printf ("%d\n", ans); }    return 0;}



Elementary school students arithmetic-java&c-statistics How many occurrences occur when two integers are added together

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.