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

Define Spanning-Tree Protocol (STP)

0 Answers  


hat is a pointer?

4 Answers   Assurgent,


here is a link to download Let_Us_C_-_Yashwant_Kanetkar

3 Answers   Microsoft,


Is it acceptable to declare/define a variable in a c header?

0 Answers  


Find MAXIMUM of three distinct integers using a single C statement

0 Answers  






What is Memory leakage ?

2 Answers   HCL,


Can stdout be forced to print somewhere other than the screen?

0 Answers  


#include<stdio.h> #include<conio.h> struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

2 Answers   Facebook,


2)#include<iostream.h> main() { printf("Hello World"); } the program prints Hello World without changing main() the o/p should be intialisation Hello World Desruct the changes should be a)iostream operator<<(iostream os, char*s) os<<'intialisation'<<(Hello World)<<Destruct b) c) d)none of the above

4 Answers   Siemens,


c program to compute Income tax and Net Salary for its employees. The company offers tax relief of Kshs. 650 for single employees and Kshs. 1,100 for married employees. The relief will be deducted from the Gross salary, to give the taxable income. This will be computed at the following rates: [10mks] Taxable Income Rate (%) <5000 0 5000-19999 6 20000-36999 9 37000 and above 16

1 Answers  


how to find sum of digits in C?

21 Answers   CTS, Infosys,


Whether there can be main inside another main?If so how does it work?

14 Answers   Sail, Wipro,


Categories