Given the array int x [ ] = {1,2,3,4,5}, write a loop that replaces every other element with the value 2, starting with the first element.
Ans:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x[] ={1,2,3,4,5};
for(int i=0;i < 5; i++) cout << x[i]/i*2 <<endl;
system("Pause");
return 0;
}
Please help.