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

main() { clrscr(); } clrscr();

6 Answers   ME, Wipro,


c program to subtract between two numbers without using '-' sign and subtract function.

1 Answers  


what is a headerfile?and what will be a program without it explain nan example?

6 Answers   Assurgent,


what is meant by c

9 Answers   INiTS,


How can a program be made to print the line number where an error occurs?

0 Answers  






write an algorithm to get a sentence and reverse it in the following format: input : I am here opuput: Here Am I note: first letter of every word is capiatlised

3 Answers  


What's a good way to check for "close enough" floating-point equality?

0 Answers   Celstream,


Difference between goto, long jmp() and setjmp()?

0 Answers   EXL,


 Illustrate it   summing the series 2+4+6+......to n terms using  (i) while loop (ii) do-while loop

2 Answers  


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

3 Answers   ME,


How can I send mail from within a c program?

0 Answers  


what is the difference between class and unio?

0 Answers   HCL, Wipro,


Categories