HackerRank C- Sum and Difference of Two Numbers




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.



  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. int main()
  6. {
  7. int a=0,b=0,sum=0,dif=0;
  8. float a1=0,b1=0,sum1=0,dif1=0;
  9. scanf("%d%d",&a,&b);
  10. scanf("%f%f",&a1,&b1);
  11. sum=a+b;
  12. sum1=a1+b1;
  13. dif=a-b;
  14. dif1=a1-b1;
  15. printf("%d %d\n",sum,dif);
  16. printf("%.1f %.1f",sum1,dif1);
  17. return 0;
  18. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube