Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

What do you mean by an Array || How to declare and initialize 1-D array in C

What do you mean by an Array ? How to declare and initialize 1-D array in C? What is a limitation of an array? Write a program to perform the addition of 3x3 matrices using an array.



Index

1. What do you mean by an Array 

2. How to declare and initialize 1-D array in C

3. What is a limitation of an array

4. Write a program to perform the addition of 3x3 matrices using an array

What do you mean by an Array 

Array:- An array is a non primitive linear type data structure. An array is basically a collection of similar type of data structure which aims to bind similar data together. It is a simple data structure where data items are accessed using indexing.

How to declare and initialize 1-D array in C

Syntax for declaration of array :-

 

                        1D array:-        data_type[no_of_element];

                        2D array:-        data_type[no_of_row][no_of_column];

                        ND array:-        datatype[number]…….n times;

 

Iinitialization of array :-

                        int arr[5] = {1,4,6,3,8};

 What is a limitation of an array

limitation of array:-

  1. Their must be a prior knowledge of number of element to be stored.
  2. An array is a static structure, means the size of the array can not be modified after its declaration.
  3. Insertion and deletion of element is complex in an array.
  4. Allocating memory more than required causes wastage of memory.

 program to perform the addition of 3x3 matrices using an array

A program to perform the addition of 3x3 matrices using an array:-

#include<stdio.h>

#include<conio.h>

int main()

{

 int matrixA[3][3],matrixB[3][3],matrixC[3][3];

 int r,c,k;

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

 {

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

  {

printf("Enter first matrix : ");

scanf("%d", &matrixA[r][c]);

  }

 }

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

 {

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

  {

printf("Enter second matrix : ");

scanf("%d", &matrixB[r][c]);

  }

 }

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

 {

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

  {

matrixC[r][c]=0;

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

matrixC[r][c] = matrixA[r][c] + matrixB[r][c];

  }

 }

printf("\n New addition matrix : \n");

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

 {

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

printf(" %d\t",matrixC[r][c]);

printf("\n");

 }

getch();

 return 0;

}

Share:

No comments:

Post a Comment

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.