how to print 2-D array using a single for loop?
Answers were Sorted based on User's Feedback
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 |
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 |
why do we use # in c-language?
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Is array a primitive data type in c?
Design a program using an array that searches a number if it is found on the list of the given input numbers and locate its exact location in the list.
consagous technology placement paper
What is a ternary operator in c?
Program to trim a given character from a string.
Why do we use header files in c?
Find greatest of two numbers using macro
What is the difference between local variable and global variable in c?
how to create c progarm without void main()?
what will be the output: main(){char ch;int a=10;printf("%d",ch);}
36 Answers Accenture, TCS, Wipro,