English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i seriously need help with combining arrays using for statements
ex.
int b[] = { 1,2,1,11,4,5};
int c[] = {8,9,4,4,7,5,7};

please i need help

2007-01-26 07:54:21 · 2 answers · asked by ~Chocolate Delight~ 2 in Computers & Internet Programming & Design

2 answers

use for

read b and c

assign c into b

print b


for(i=7;i<=14;i++){
b[i]=c[i-6]
}

2007-01-26 08:35:45 · answer #1 · answered by iyiogrenci 6 · 0 1

as array is kind of pointer pointing to certain location. so in C you need to be careful before you pass the upper limit. Compiler will not complain about the limit but will end in runtime error if you go beyond an upper limit.

e.g
int a[4]={1,2,3,4};

for (int i=0;i<7;i++)
cout<
so for your case here the simple programe

int a[4]={1,2,3,4};
int b[5]={1,2,3,4,5};

int temp [9]; //contains array a & b

int i=0; //counter
while(1)
{

if(i<4)
{
temp[i]=a[i];
}

if(i>=4)
temp[i]=b[i];

if(i>=9)
break;

i++;
}

2007-01-26 18:20:51 · answer #2 · answered by ITguru 2 · 0 0

fedest.com, questions and answers