Codechef Add Two Numbers problem solution

In this Codechef Add, Two Numbers problem solution Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.

The task is very simple: given two integers A and B, write a program to add these two numbers and output it.

Codechef Add Two Numbers problem solution


Problem solution in Python.

T = int(input())
for tc in range(T):
    # Read integers a and b.
    (a, b) = map(int, input().split(' '))
    
    ans = a + b
    print(ans)



Problem solution in Java.

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


// Remember that the class name should be "Main" and should be "public".
public class Main {
    public static void main(String[] args) {
        // System.in and System.out are input and output streams, respectively.
        InputStream inputStream = System.in;

        InputReader in = new InputReader(inputStream);

        // Read the number of test casese.      
        int T = in.nextInt();
        while (T-- > 0) {
            // Read the numbers a and b.
            int a = in.nextInt();
            int b = in.nextInt();
            
            // Compute the sum of a and b.
            int ans = a + b;
            System.out.println(ans);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}



Problem solution in C++.

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() 
{
   int t;
   cin>>t;
   int a,b;
   while(t--){
    int sum=0;
    cin>>a>>b;
    sum=a+b;
    cout<<sum<<"\n";
   }
   return 0;
}



Problem solution in C.

#include <stdio.h> 

int main() {
    // Read the number of test cases.
    int T;
    scanf("%d", &T);
    while (T--) {
        // Read the input a, b
        int a, b;
        scanf("%d %d", &a, &b);

        // Compute the ans.
        int ans = a + b;
        printf("%d\n", ans);
    }

    return 0;
}


Post a Comment

0 Comments