+ 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
4 odpowiedzi
+ 1
~ swim ~ thanks lot bro
+ 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
0
No bro if i give 5 number input like 12345 results should be 54321 but it shows 054321 it's automatically put zero
0
Edward Finkelstein thanks bro