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

Give basis knowledge of web designing ...

0 Answers   HCL,


Print all numbers which has a certain digit in a certain position eg: number=45687 1 number=4 2 number=5 etc

4 Answers  


why programs in c are running with out #include<stdio.h>? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

0 Answers  


c program to print a name without using semicolon

9 Answers   TCS, Wipro,


What is call by reference in functions?

1 Answers  






How does the C program handle segmentation faults?

2 Answers  


what is the associativity of bitwise OR operator?

1 Answers  


what is the difference between const char *p, char const *p, const char* const p

5 Answers   Accenture, Aricent, CTS, Geometric Software, Point Cross, Verizon,


Why is c still so popular?

0 Answers  


What is LINKED LIST? How can you access the last element in a linked list?

0 Answers   ADP,


write a program that will print %d in the output screen??

9 Answers   Infosys,


Dear Sir, we are required the bubble sorting programs Regs Prem

1 Answers  


Categories