199k views
1 vote
Write a program that accepts three decimal numbers as input and outputs their sum.

User Dredok
by
4.8k points

2 Answers

3 votes

Answer:

C++ code

Step-by-step explanation:

C++ code

#include <iostream>

#include <cstdlib>

using namespace std;

int main(){

double first,second,third;

cout<<"Enter first Decimal :";

cin>>first;

cout<<"Enter second Decimal :";

cin>>second;

cout<<"Enter third Decimal :";

cin>>third;

cout<<"Sum of three decimal = "<<first+second+third;

return 0;

}

Code Explanation

Decimal numbers are stored in double data types.

So first declare three variables and then get input by using cin from command line.

At the end display there sum by addition of all three variables.

Output

Enter first Decimal :10.22

Enter second Decimal :20.22

Enter third Decimal :9.99

Sum of three decimal = 40.43

User Chris Mohr
by
5.0k points
1 vote

Answer:

i = 0

total = []

print('Enter 3 decimal numbers')

while i < 3:

num = float(input(str(i+1)+')'))

i += 1

total.append(num)

print('sum = ',sum(total))

Step-by-step explanation:

The programming language used is python.

The code prompts the user to Enter three decimal numbers, accepts the numbers and then outputs the sum.

A WHILE loop is used to collect the three numbers and the numbers are stored in a list using the append method. finally we make use of the list attribute sum, to evaluate the sum of the three numbers inputted.

A picture is attached for you to see how the code behaves.

Write a program that accepts three decimal numbers as input and outputs their sum-example-1
User Binier
by
6.1k points