how to print 2-D array using a single for loop?
Answer Posted / vinay joshi
void main()
{
int i,j=-1;
int a[3][2];
label:j++;
for(i=0;i<2;i++)
{
if(j>3)
{
//printf("%d",j);
break;
}
printf("enter the element:");
scanf("%d",&a[j][i]);
if(i==1 )
{
goto label;
}
}
j=-1;
label2:++j; printf("\n");
for(i=0;i<2;i++)
{
if(j>3)
{
break;
}
printf("%d\t",a[j][i]);
if(i==1)
{
goto label2;
}
}
getch();
}
| Is This Answer Correct ? | 1 Yes | 4 No |
Post New Answer View All Answers
What is a scope resolution operator in c?
What does it mean when a pointer is used in an if statement?
Is there any demerits of using pointer?
How are 16- and 32-bit numbers stored?
Why is c not oop?
Where static variables are stored in c?
Is c call by value?
How many levels deep can include files be nested?
Explain what is operator promotion?
Tell us two differences between new () and malloc ()?
What is getche() function?
What is a lookup table in c?
What is #line in c?
Explain what standard functions are available to manipulate strings?
What are volatile variables in c?