adplus-dvertising
sum and difference of two numbers hackerrank solution

Sum and Difference of Two Numbers – Hackerrank Solution

Sum and Difference of Two Numbers – Hackerrank Solution Explain Video :

Sum and Difference of Two Numbers Hackerrank Solution , We Discuss About That Sum and Difference of Two Numbers Hackerrank Solution in C

Problem :

  • Objective
  • Task
  • Output Format
  • Input Format
  • Sample Input 0
  • Sample Output 0
  • Solution

Objective :

The fundamental data types in c are int, float and char. Today, we’re discussing int and float data types.

The printf() function prints the given statement to the console. The syntax is printf(“format string”,argument_list); . In the function, if we are using an integer, character, string or float as argument, then in the format string we have to write %d (integer), %c (character), %s (string), %f (float) respectively.

The scanf() function reads the input data from the console. The syntax is scanf(“format string”,argument_list);. For ex: The¬†scanf(“%d”,&number)¬†statement reads integer number from the console and stores the given value in variable number.

To input two integers separated by a space on a single line, the command is scanf(“%d %d”, &n, &m), where n and m¬†are the two integers.

Task:

Your task is to take two numbers of int data type, two numbers of float data type as input and output their sum:

  1. Declare 4 variables: two of type int and two of type float.
  2. Read 2 ¬†lines of input from stdin (according to the sequence given in the ‘Input Format’ section below) and initialize your 4¬†variables.
  3. Use the + and –¬†operator to perform the following operations:
    • Print the sum and difference of two int variable on a new line.
    • Print the sum and difference of two float variable rounded to one decimal place on a new line.

Input Format:

The first line contains two integers.
The second line contains two floating point numbers.

Sample Input 0:

10 4

4.0 2.0

Sample Output 0:

14 6

6.0 2.0

Sum and Difference of Two Numbers HackerRank Solutions

Solution Solution :

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{

int a,b;
float c,d;
//printf(“\n Enter two integer numbers “);
scanf(“%d %d”,&a,&b);
printf(“%d %d”,a+b,a-b);
//printf(“\n Enter two float numbers “);
scanf(“%f %f”,&c,&d);

printf(“\n%.1f %.1f”,c+d,c-d);
return 0;
}

 

Do Solve in Hackerrank – Click Here

Get More Solution : Click Me

Explanations : Click Me To Get Explain Video

Firstly, You have to Copy The Code Here and Go to Your Sum and Difference of Two Numbers Hackerrank Solution Questions Problem. Then You Have to go Submission Page. Now You Have Pasted this Copy Code and Run This Code by Compiler. You Can See All Task Should be Done. All Private and Public Cases Passed. Then Submit Your Code Finally.

What is #Include<stdio.h> ?

#include<stdio.h> is used to included header file in c programming language. It is a Mandetory. It is also Compiler Directives to Include INPUT/OUTPUT related function in our Program. The¬†stdio.h¬†is a file with “.h” extension which is contain the prototypes [not definition] of standard input-output functions used in c program.

For Others File We Have to Discuss in Future Articles. Visit Our Official Website.

Sum and Difference of Two Numbers Hackerrank Solution is a Solution Where You Can See The Code of Sum and Difference of Two Numbers Hackerrank Solution and Understand The Code Level. If You Want Others Code of Hackerrank Solution In C then You Can Visit Our Official Website For More Information About Hackerrank Solution In C.

What is int main() ?

‚Äėint main‚Äô means our perform must come thusme whole number at the top of the execution and that we do so by returning zero at the top of the program. zero is that the normal for the ‚Äúsuccessful execution of the program‚ÄĚ.

Also You Can Read – Database Management System (DBMS)

What is Printf and Scanf ?

The printf() and scanf() functions area unit used for input and output in C language. each functions area unit inherent library functions, outlined in stdio.h (header file).

What is Compiler ?

The language processor that reads the whole program written in application-oriented language as a full in one go and interprets it into identical program in machine language is named a Compiler. Example: C, C++, C#, Java. compilers/assemblers area unit themselves package, and reside where they were put in on the pc. that additionally implies that you just will have as many/few of every as you wish.

How “Sum and Difference of Two Numbers Hackerrank Solution” In C program works?

  • The #include is a preprocessor command that tells the compiler to include the contents of stdio.h (standard input and output) file in the program.
  • The stdio.h file contains functions such as scanf() and printf() to take input and display output respectively.
  • If you use the printf() function without writing #include <stdio.h>, the program will not compile.
  • The execution of a C program starts from the main() function.
  • printf() is a library function to send formatted output to the screen. In this program, printf() displays C Language Welcome To C!!
    text on the screen.
  • The¬†return 0;¬†statement is the¬†“Exit status”¬†of the program. In simple terms, the program ends with this statement.

The #include could be a preprocessor command that tells the compiler to incorporate the contents of stdio.h (standard input and output) enter the program.
The stdio.h file contains functions like scanf() and printf() to require input and show output severally.
If you utilize the printf() perform while not writing #include , the program won’t compile.
The execution of a program starts from the main() perform.
printf() could be a library perform to send formatted output to the screen. during this program, printf() displays hello, World! in C text on the screen.
The¬†return 0;¬†statement is the¬†“Exit status” of the program. In straightforward terms, the program ends with this statement.

Hackerrank Answer Sum and Difference of Two Numbers Hackerrank Solution

Hello World may be a sample program designed to acquaint users with most programming languages. Beginners ar introduced to the essential syntax of a programing language by learning the way to print out “Hello World” on the device screen. printf(“Hello World”); This line tells the compiler to show the message “Hello World” on the screen. This line is termed an announcement in C. each statement is supposed to perform some task.

Conclusion :

So, Learners today you have learned about basic Sum and Difference of Two Numbers. Now you can solve Sum and Difference of Two Numbers If you still have any doubt regarding the problem Just Watch Explanation Video, then Till any Queries , feel free to contact in the comment section.

Disclaimer:

The above problem Sum and Difference of Two Numbers is generated by HackerRank but the solution is provided by Us. (Check DMCA for Others)

Related Posts

4 thoughts on “Sum and Difference of Two Numbers – Hackerrank Solution

  1. The next time I learn a blog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my choice to read, but I really thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about something that you could repair in the event you werent too busy searching for attention.

  2. Yesterday, while I was at work, my cousin stole my iPad and tested to see if it can survive a 25 foot drop, just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views. I know this is entirely off topic but I had to share it with someone!

Leave a Reply

Your email address will not be published.