O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Do While Loop Write a Do While loop that allows the user to enter floa.docx

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

Confira estes a seguir

1 de 2 Anúncio

Do While Loop Write a Do While loop that allows the user to enter floa.docx

Baixar para ler offline

Do While Loop
Write a Do While loop that allows the user to enter floating point numbers greater than 0 and sums these numbers and prints the sum after the loop. The loop should exit after a number less than or equal to 0 is entered.
Please do not add in values less than or equal to zero.
Sample Output #1:
Enter Positive Number to Add or Enter Zero or Negative Number to End: 99.0
Enter Positive Number to Add or Enter Zero or Negative Number to End: 67.5
Enter Positive Number to Add or Enter Zero or Negative Number to End: 0
Sum of Entered Numbers: 166.5
Solution
#include int main() { double firstNumber, secondNumber, productOfTwoNumbers; printf(\"Enter two numbers: \"); // Stores two floating point numbers in variable firstNumber and secondNumber respectively scanf(\"%lf %lf\",&firstNumber, &secondNumber); // Performs multiplication and stores the result in variable productOfTwoNumbers productOfTwoNumbers = firstNumber * secondNumber; // Result up to 2 decimal point is displayed using %.2lf printf(\"Product = %.2lf\", productofTwoNumbers); return 0; }
.

Do While Loop
Write a Do While loop that allows the user to enter floating point numbers greater than 0 and sums these numbers and prints the sum after the loop. The loop should exit after a number less than or equal to 0 is entered.
Please do not add in values less than or equal to zero.
Sample Output #1:
Enter Positive Number to Add or Enter Zero or Negative Number to End: 99.0
Enter Positive Number to Add or Enter Zero or Negative Number to End: 67.5
Enter Positive Number to Add or Enter Zero or Negative Number to End: 0
Sum of Entered Numbers: 166.5
Solution
#include int main() { double firstNumber, secondNumber, productOfTwoNumbers; printf(\"Enter two numbers: \"); // Stores two floating point numbers in variable firstNumber and secondNumber respectively scanf(\"%lf %lf\",&firstNumber, &secondNumber); // Performs multiplication and stores the result in variable productOfTwoNumbers productOfTwoNumbers = firstNumber * secondNumber; // Result up to 2 decimal point is displayed using %.2lf printf(\"Product = %.2lf\", productofTwoNumbers); return 0; }
.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Semelhante a Do While Loop Write a Do While loop that allows the user to enter floa.docx (20)

Mais de wviola (20)

Anúncio

Mais recentes (20)

Do While Loop Write a Do While loop that allows the user to enter floa.docx

  1. 1. Do While Loop Write a Do While loop that allows the user to enter floating point numbers greater than 0 and sums these numbers and prints the sum after the loop. The loop should exit after a number less than or equal to 0 is entered. Please do not add in values less than or equal to zero. Sample Output #1: Enter Positive Number to Add or Enter Zero or Negative Number to End: 99.0 Enter Positive Number to Add or Enter Zero or Negative Number to End: 67.5 Enter Positive Number to Add or Enter Zero or Negative Number to End: 0 Sum of Entered Numbers: 166.5 Solution #include int main() { double firstNumber, secondNumber, productOfTwoNumbers; printf("Enter two numbers: "); // Stores two floating point numbers in variable firstNumber and secondNumber respectively scanf("%lf %lf",&firstNumber, &secondNumber); // Performs multiplication and stores the result in variable productOfTwoNumbers productOfTwoNumbers = firstNumber * secondNumber; // Result up to 2 decimal point is displayed using %.2lf printf("Product = %.2lf", productofTwoNumbers); return 0; }

×