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!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ???

19th May 2020, 8:38 AM
Karan Dewangan
Karan Dewangan - avatar
2 Answers
+ 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
19th May 2020, 8:51 AM
Jefferson Jadoc
Jefferson Jadoc - avatar
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
19th May 2020, 8:46 AM
Ahmed Muhammed
Ahmed Muhammed - avatar