Skip to main content
added 39 characters in body
Source Link
Andrew Tomazos
  • 69.3k
  • 46
  • 208
  • 348
for(int i = 1; i <= num; i++) { cout<<i<<" element = ";  // cin>>data[i]; }WRONG 

I think you mean:

for(int i = 0; i < num; i++) { cout<<i<<" element = "; // cin>>data[i]; }RIGHT 

Arrays in C are 0-indexed remember.

for(int i = 1; i <= num; i++) { cout<<i<<" element = ";  cin>>data[i]; } 

I think you mean:

for(int i = 0; i < num; i++) { cout<<i<<" element = ";  cin>>data[i]; } 
for(int i = 1; i <= num; i++) { // WRONG 

I think you mean:

for(int i = 0; i < num; i++) { // RIGHT 

Arrays in C are 0-indexed remember.

Source Link
Andrew Tomazos
  • 69.3k
  • 46
  • 208
  • 348

for(int i = 1; i <= num; i++) { cout<<i<<" element = "; cin>>data[i]; } 

I think you mean:

for(int i = 0; i < num; i++) { cout<<i<<" element = "; cin>>data[i]; }