vilfred
Member level 1
Hi...I need to compare array with sequence of numbers using if condition in C. I tried the following steps but it doesn't produce the correct results please give me the right answer.
a).
b).
a).
Code:
int a[3]={4,1,2};
int b[3]={1,2,3};
if (a[0] ==4) // checking the first element in array
{
if (a[1] ==1) // checking second element in array
{
if(a[2]==2) // checking third element in array
{
printf("the entered numbers are in 'a' array\n");
}
}
}
else
{
if (b[0] == 1)
{
if (b[1] == 2)
{
if (b[2] == 3)
{
printf("the entered numbers are in 'b' array\n");
}
}
}
b).
Code:
int a[3]={4,1,2};
int b[3]={1,2,3};
if(a[3] == 4,1,2)
{
printf("the entered numbers are in 'a' array\n");
}
else
{
if(b[3] == 1,2,3)
{
printf("the entered numbers are in 'b' array\n");
}
Last edited by a moderator: