Arrays 2

What wrong with this program..........?
Any one help
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int n[5],m[5],b[10];
cout<<"Enter OOD Numbers in array:";
for(int i=0;i<5;i++)
cin>>n[i];
cout<<"Enter Even Numbers in 2nd array:";
for(int i=0;i<5;i++)
cin>>m[i];
for(int i=0;i<10;i++){
for(int j=0;j<i;j++)
{
if(n[j]<m[j])
b[i]=n[j];
else
b[i]=m[j];
}
}
for(int i=0;i<10;i++){
cout<<b[i]<<" ";
}
}
Last edited on
Not sure what you are trying to accomplish but in your inner for loop your condition is j<i when the value of j and i are both 0.
closed account (Dy7SLyTq)
a) use code tags.
b) what is happening that you dont like? is it compiling? is it giving bad output? is it skipping input?
Try this.. You may have to correct the math formulas.. yours were kind of jumbled..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<conio.h>

using namespace std;


int main() {

    int n[5],m[5],b[10];
    cout<<"Enter 5 ODD Numbers in array:";
    for(int i=0; i<5; i++) {
        cin>>n[i];
    }

    cout<<"Enter 5 Even Numbers in 2nd array:";
    for(int i=0; i<5; i++) {
        cin>>m[i];
    }
    for(int i=0; i<10; i++) {
        for(int j=0; j<i; j++) {
            if(n[j]<m[j]) {
                b[i]= n[j];
            } else {
                b[i]=m[j];
            }
        }
    }


    for (int i=0; i<10; i++) {
        cout<< b[i] << " ";
    }
}
Not sure what you are trying to achieve here, but you will have problem here:

if(n[j]<m[j]) {
b[i]= n[j];
} else {
b[i]=m[j];
}

As value of j can go beyond 5 and your array of m and n are of size 5.
I m trying to arrange two arrays in one array............in ascending order
Last edited on
Topic archived. No new replies allowed.