# Thread: Need help on making an array in a loop

1. ## Need help on making an array in a loop

here's my code
Code:
```#include<stdio.h>
int main()
{
int setA[1000],setB[1000],a,b,n=1,m=1,i1,i2;
printf("Enter size of set A: ");
scanf("%d",&a);
for (i1=0;i1<a;i1++)
{
printf("Enter A%d: ",n);
scanf("%d",&setA[i1]);
n++;
}
printf("Enter size of set B: ");
scanf("%d",&b);
for (i2=0;i2<b;i2++)
{
printf("Enter B%d: ",m);
scanf("%d",&setB[i2]);
m++;
}
printf("\n{");
for(i1=0;i1<a;i1++)
{
if (i1 != a-1)
printf("%d,",setA[i1]);
else if (i1 == a-1)
printf("%d",setA[i1]);
}
printf("} x {");
for(i2=0;i2<b;i2++)
{
if (i2 != b-1)
printf("%d,",setB[i2]);
else if (i2 == b-1)
printf("%d",setB[i2]);
}
printf("} = {");
for(i1=0;i1<a;i1++)
{
for(i2=0;i2<b;i2++)
{
if ((i1 != a-1)||(i2 != b-1))
{
printf("(%d,%d),",setA[i1],setB[i2]);
}
else if ((i1 == a-1)&&(i2 == b-1))
{
printf("(%d,%d)",setA[i1],setB[i2]);
}
}
}
printf("}\n");
printf("The intersection/s of sets {");
for(i1=0;i1<a;i1++)
{
if (i1 != a-1)
printf("%d,",setA[i1]);
else if (i1 == a-1)
printf("%d",setA[i1]);
}
printf("} and {");
for(i2=0;i2<b;i2++)
{
if (i2 != b-1)
printf("%d,",setB[i2]);
else if (i2 == b-1)
printf("%d",setB[i2]);
}
printf("} is/are {");
for(i1=0;i1<a;i1++)
{
for(i2=0;i2<b;i2++)
{
if (setA[i1]==setB[i2])
{
printf("%d,",setA[i1]);
//instead of using printf here I wanted to make it an array
}
}
}
printf("}\n");
return 0;
}```

2. Yes, and.... ???

3. This sounds like one of the "Can i haz" posts.

4. What they said.

Anyway, what is this supposed to do, print setA[i1] whether i1 is or isn't equal to a-1? Seems funny...
Code:
```        if (i1 != a-1)
printf("%d,",setA[i1]);
else if (i1 == a-1)
printf("%d",setA[i1]);```