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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of c language?

561


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

679


Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58

1126


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1712


Is main is user defined function?

601






Is there a built-in function in C that can be used for sorting data?

749


praagnovation

1785


Do you know the difference between malloc() and calloc() function?

617


What functions are in conio h?

665


What does return 1 means in c?

591


How do I get a null pointer in my programs?

626


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

774


What is pointer to pointer in c with example?

556


What are global variables and how do you declare them?

623


How can I send mail from within a c program?

587