0% found this document useful (0 votes)
79 views3 pages

2d Input and Output

Input means to provide the program with some data to be used in the program Output means to display data on screen or write the data to a printer or a file. C programming language provides many built-in functions to read any given input and to display data on screen when there is a need to output the result. In this tutorial, we will learn about such functions, which can be used in our program to take input from user and to output the result on screen.

Uploaded by

ayan shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views3 pages

2d Input and Output

Input means to provide the program with some data to be used in the program Output means to display data on screen or write the data to a printer or a file. C programming language provides many built-in functions to read any given input and to display data on screen when there is a need to output the result. In this tutorial, we will learn about such functions, which can be used in our program to take input from user and to output the result on screen.

Uploaded by

ayan shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

How to take 2-D array elements as input In C |

Programmerdouts
programmerdouts.blogspot.com/2019/06/how-to-take-2-d-array-elements-as-input.html

How to take 2-D array elements as input?


As we used loops for taking input of 1-Dimensional array elements,
same like 1-D array we will use loops for 2-D array as well.
As we know using loops for taking input is a good approach and it is
more efficient than the normal approach of using number of
scanf() functions.
For taking input of element of 2-D array, we have to use Nested for
loop

Syntax:

for(initialization; condition; increment )


{

for(initialization; condition; increment)


{
//body of this for loop

}
}

Let's take some elements as inputs of 2-d array.and print

Q:declare a 2-d array of 3 rows and 4 cols and take their element as input
from the user and print them on screen like an table.?

1/3
#include<stdio.h>

void main()
{ //integer type of multi-dimensional array having 3 rows and 4 columns.
int i,j;
int arr[3][4];

for(i = 0; i < 3; i++)


{
for(j = 0; j<4; j++)
{ printf("enter the element:"); //for each value of i this for loop will iter 4
times.
scanf("%d",&arr[i][j]); //means total iteration will be 3*4=12 ,it will
take 12 iteration.
}
}

// printing array elements

printf("Array Elements are:")


for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
printf("%d\t",arr[i][j]);
}
//after completing above loop cursor should go in New line.
printf("\n");
}
}

Output:

enter the element:1


enter the element:2
enter the element:3
enter the element:4
enter the element:5
enter the element:6
enter the element:7
enter the element:8

2/3
enter the element:9
enter the element:10
enter the element:11
enter the element:12

Array Elements are:


1 2 3 4
5 6 7 8
9 10 11 12
this is how we take element of 2-D array as input.
Do programs on taking inputs of element of 2-D array ,for
understanding more better.
It looks hard but ,as you will start doing programs you will find it
easy and you will have fun while doing it.

Practice Programs
Programs regarding Arrays
Programs Regarding 2d arrays
Programs regarding matrix
And lot more

3/3

You might also like