SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Solve me second : Hacker Rank Problem Solution
Solve me second : Hacker Rank Problem Solution
C Implementation:
#include
#include
#include
#include
/* function to find the sum of two numbers */ int solveMeSecond(int a, int b) { return a+b; } int main() { int t,i; /* get the number of test cases from the user */ scanf("%d",&t); int num1,num2; int sum; /* for values from 0 to entered test case*/ for ( i = 0;i < t; i++ ) { /* get the two numbers */ scanf("%d %d",&num1,&num2); /* calculate the sum of two numbers by calling function solveMeSecond*/ sum = solveMeSecond(num1,num2); /* print the result., which is the sum of entered two numbers */ printf("%d\n",sum); } return 0; }
Python Implementation:
# function to calculate the sum of two accepted numbers from the user def solveMeSecond(a,b): return a+b # get the number of integers rom the user n = int(raw_input()) #faster than n = input() , since input() executes the line as python command # get the numbers from the user for i in range(0,n): a, b = raw_input().split() # conver the two numbers into integer type a,b = int(a),int(b) # call the function solveMeSecond to compute the sum of two numbers res = solveMeSecond(a,b) # print the result of the entered numbers print res
PREVIOUS
NEXT
HOME