Must be 6 bugs in the program below. Could someone make a list and corrections?
ID: 3872514 • Letter: M
Question
Must be 6 bugs in the program below. Could someone make a list and corrections? NOTE: PLEASE DON'T ANSWER MY QUESTIONS IF YOU'RE NOT SURE ABOUT THE SOLUTION. THANK YOU #include using namespace std; void display(long a[5],int times){ cout << times << "-th loop result : "; for(int i=0;i<5;i++){ cout << "a[" << i <<"]= " << a[i] << " " ; } cout << endl; } int main(){ long int product; long productArray[5]; for( int i=1; i<=5 ; i++){ product *=i; productArray[i] = product; display(productArray,i); } int i=0,j; int index[5]; while(j<5){ int remainder = productArray[i]%4; if(remainder=0){ index[j] = i; j++; } i++; } cout << "values in productArray( mod 4 equal to 0) = "; while(j<5){ cout << "a[" << productArray[index[j]] << "] "; j++; } cout << endl; return 0; }
Explanation / Answer
Below all the errors:
1. Line 1 expect file name after include keyword.
2. Line 6 'cout' not found or not declared with in the scope.
3. Line 12, 'endl' not found or not declared with in the scope.
4. Line 39 'cout' not found or not declared with in the scope.
5. Line 45, 'endl' not found or not declared with in the scope.
All above errors get resolved if we add filename 'iostream' after #include.
#include <iostream>
using namespace std;
void display(long a[5],int times){
cout << times << "-th loop result : ";
for(int i=0;i<5;i++){
cout << "a[" << i <<"]= " << a[i] << " " ;
}
cout << endl;
}
int main(){
long int product;
long productArray[5];
for( int i=1; i<=5 ; i++){
product *=i;
productArray[i] = product;
display(productArray,i);
}
int i=0,j;
int index[5];
while(j<5){
int remainder = productArray[i]%4;
if(remainder=0){
index[j] = i;
j++;
}
i++;
}
cout << "values in productArray( mod 4 equal to 0) = ";
while(j<5){
cout << "a[" << productArray[index[j]] << "] ";
j++;
}
cout << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.