help with array ?

Hi
Can anyone help me with this code please ?

char a[3]={A,B,C};
char b[3]={@,#,$};


i need the output like this :

A@,A#,A$,B@,B#,B$,C@,C#,C$

Following is close, you get a comma at the end.

1
2
3
4
5
6
char a[3]={'A','B','C'};
char b[3]={'@','#','$'};

for( int i=0; i < 3; i++ )
  for( int j=0; j < 3; j++ )
    printf( "%c%c,", a[i], b[j] );

@hexori

Doing it like this, gets the exact results you were looking for..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Print chars.cpp : main project file.

#include <iostream>

using namespace std;

int main()
{
    char a[3]={'A','B','C'};
	char b[3]={'@','#','$'};

for( int i=0; i < 3; i++ )
{
    for( int j=0; j < 3; j++ ) 
	{
	printf( "%c%c", a[i], b[j] );
	 if(i!=2 || j!=2)
		 printf(",");
	}
}
printf("\n");
}
binarybob350 & whitenite1

It works !
Thank you so much , I appreciate your help ..
Topic archived. No new replies allowed.