Write a program that accepts three decimal numbers as input and outputs their sum.
The following content is partner provided
Answers
import java.util.*;
public class sum
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
double n1,n2,n3,sum;
System.out.println("Enter three decimal numbers:");
n1 = in.nextDouble();
n2 = in.nextDouble();
n3 = in.nextDouble();
sum = n1 + n2 + n3;
System.out.println("Sum: "+sum);
}
}
//Please mark it as brainliest...
//
Below are the program in c language for the above question:
Explanation:
#include <stdio.h>
int main()
{
float a,b,c;// variable declaration of float type which store decimal value
scanf("%f %f %f",&a,&b,&c);// take three input as decimal value
printf("%f",a+b+c);// prinnt the addition of decimal value
return 0;
}
Output:
- If the user inputs 2.3, 3.2 and 4.5 then the output is 10.000000
- If the user inputs 2.3, 2.3 and 2.3 then the output is 6.900000
In the above program, scanf() is used to take input of three float variable. It is because there is %f, which represents the value in float. The printf() is used to print the value.
Learn More:
- Definition of C Program: brainly.in/question/637147
- c program: brainly.in/question/9996665