how to print 2-D array using a single for loop?

Answers were Sorted based on User's Feedback



how to print 2-D array using a single for loop?..

Answer / tknowledge05

#include<stdio.h>
#include<conio.h>
void main()
{

int a[3][3]={2,4,5,7,2,9,2,3,2};
int f=0,i;
printf("\n");
for(i=0;f!=3;i++)
{

if(i==3)
{f++;
printf("\n");
i=0;
}
printf("%d ",a[f][i]);
}




getch();
}

Is This Answer Correct ?    21 Yes 4 No

how to print 2-D array using a single for loop?..

Answer / 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

More C Interview Questions

find largest element in array w/o using sorting techniques.

3 Answers   Zycus Infotech,


What is the relation between # and include<stdio.h>

5 Answers   HCL,


Explain Linker and Loader

5 Answers  


What are register variables? What are the advantage of using register variables?

0 Answers   TISL,


What is c definition?

0 Answers  






can you change name of main()?how?

3 Answers   HCL, Siemens,


how to write a data 10 in address location 0x2000

3 Answers  


what is the difference between %d and %*d in c languaga?

7 Answers   TCS,


‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

0 Answers  


What is the symbol indicated the c-preprocessor?

0 Answers  


What is string concatenation in c?

0 Answers  


How to print India by nested loop? I IN IND INDI INDIA

4 Answers   NIIT, Wipro,


Categories