+ 1

Data structure doubt

#include "iostream" using namespace std; int main() { int count; int a[10] = {}; int b[10] = {}; cin>>count; cout<<"enter number\n"; for (int i = 0; i <count; i++) { cin>>a[i]; } int k = count; int n = 0; while (k >= 0 && n <=count) { b[n] += a[k]; n++; k--; } for (int j = 0; j <= count ; j++) { printf("%d",b[j]); } } If I run this code it's automatically put zero at last index any one know what's wrong in this code

26th Jul 2020, 6:36 AM
Vek
Vek - avatar
4 odpowiedzi
+ 1
~ swim ~ thanks lot bro
26th Jul 2020, 7:12 AM
Vek
Vek - avatar
+ 1
#include "iostream" using namespace std; int main() { int count; cout<<"enter number\n"; cin>>count; cout << count << endl; int a[count]={}; int b[count]={}; for (int i = 0; i <count; i++) { cin>>a[i]; } int k = count; int n = 0; while (k >= 0 && n <count) { b[n] += a[k-1]; n++; k--; } for (int j = 0; j < count ; j++) { printf("%d",b[j]); } } https://code.sololearn.com/cUanEeI2I9j4/#cpp
26th Jul 2020, 7:22 AM
Edward Finkelstein
Edward Finkelstein - avatar
0
No bro if i give 5 number input like 12345 results should be 54321 but it shows 054321 it's automatically put zero
26th Jul 2020, 6:56 AM
Vek
Vek - avatar
0
26th Jul 2020, 8:11 AM
Vek
Vek - avatar