Arrays

Hi
friend, I am trying a programme with that takes tree arrays of same even lengths and adds the values at odd indexes and save at even index of 3rd array and voice virsa........
what will be the logic i have tried it a lot of time not worked................
If you show us the code that you've already written, we can help you work out what's wrong with it.

Remember to use code tags when you post your code, to make it readable.
Hi, i got a logic for you but i will not show you a logic. Follow below simple logic.

Steps:

1. Initialize all arrays by zero in order to avoid junk/garbage value using while/for looping structures.

2. Take inputs in all arrays and make a check so that array size don't get odd i.e. user don't enter odd no of inputs. If so, force user to give more input of neglect most recent input to make the. array of even no's. Also generate a warning message about it.[ just for good programming practice :L ]

3. Start a loop while/for anyone which suits yourself. Also add relative elements.
e.g.
1
2
for (initialization ; condition; iteration)
     Sum=array1[iterator]+array2[iterator];

4. Also in above loop use 'if' to place values of SUM onto odd indexes of third array.

5. Print the array3
Last edited on
ok,that the code
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
void main()
{
clrscr();
int a[4],b[4],c[4];
int j=3;
for(int i=0;i<4;i++)
{
cout<<"Enter Value for indux("<<i<<") of Arrays a,b";
cin>>a[i];
cin>>b[i];
}
for(i=0;i<4;i++)
{
cout<<"\nThe Value at indux("<<i<<") of Arrays a is ="<<a[i]<<"\nThe Value at indux("<<i<<") of Arrays b is ="<<b[i];
}
for(j=0;j<4;j++)
{
for(i=0;i<4;i++)
{
if(/*j%2==0&&*/j>=0&&j<=1&&/*i%2==1&&*/i>=0&&i<=1)
c[j]=a[i]+b[i];
if(/*j%2==1&&*/j>=2&&j<=3&&/*i%2==0&&*/i>=2&&i<=3)
c[j]=a[i]+b[i];
}
}
for(j=0;j<4;j++)
{
cout<<"\nThe Value at index ("<<j<<") of Array c is ="<<c[j];
}
getch();
}
Topic archived. No new replies allowed.