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.
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
-
- int main()
- {
- int a=0,b=0,sum=0,dif=0;
- float a1=0,b1=0,sum1=0,dif1=0;
- scanf("%d%d",&a,&b);
- scanf("%f%f",&a1,&b1);
- sum=a+b;
- sum1=a1+b1;
- dif=a-b;
- dif1=a1-b1;
- printf("%d %d\n",sum,dif);
- printf("%.1f %.1f",sum1,dif1);
-
-
- return 0;
- }