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

How the C program can be compiled?

11 Answers   HP,


Can a function argument have default value?

0 Answers   Genpact,


This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory

0 Answers  


main() { char p[] = "hello world!"; p = "vector"; printf("%s",p); }

2 Answers   Vector, Vector India,


what is differnence b/w macro & functions

1 Answers  






What is a pragma?

0 Answers  


Explain demand paging.

1 Answers   Agilent,


What is the difference between text files and binary files?

0 Answers  


Explain the use of #pragma exit?

0 Answers  


When should a type cast not be used?

0 Answers  


11. Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage

7 Answers   Accenture,


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

0 Answers   Wipro,


Categories