double d=10; double darr[]={3.0,0.5,2.0,1.5}; for(int i=0;i<4;i++){d*=darr[I];} cout<<d; | SoloLearn: Learn to code for FREE!

+2

double d=10; double darr[]={3.0,0.5,2.0,1.5}; for(int i=0;i<4;i++){d*=darr[I];} cout<<d;

Why is output 4.5 ???

5/19/2020 8:38:33 AM

Karan Dewangan

2 Answers

New Answer

+1

The output is 45 because you can see in the for loop it use the assignment operator which is Multiplication (*=) Then the assignment statement is d*=darr[i] Its look like these when the loop iterate 10 *=3.0 =30 10 *=0.5 =15 10 *=2.0 =30 10 *=1.5 =45

0

#include <iostream> using namespace std; int main() { double d=10; double darr[]={3.0,0.5,2.0,1.5}; for(int i=0;i<4;i++){ d*=darr[i]; } cout<<d; } 10 * 3.0 * 0.5 * 2.0 * 1.5 = 45.0