0% found this document useful (0 votes)
6 views2 pages

CPR Experiment 7

Uploaded by

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

CPR Experiment 7

Uploaded by

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

CPR Experiment 7:

Aim: a) Program to demonstrate Array 1D,


b) Program to demonstrate Array 2D
Theory:

An array in C is a fixed-size collection of similar data items stored in contiguous memory


locations.

It can be used to store the collection of primitive data types such as int, char, float, etc., and
also derived and user-defined data types such as pointers, structures, etc.

Arrays can be of 1 dimensional, 2 dimensional or multidimensional.

Syntax to create a 1D array in C:

datatype arrayname[size];

Syntax to declare 2D array :

datatype array_name[size1] [size2];

Where size1 is size of the first dimension(rows) and size2 is size of the second
dimension(columns)

Exercise:

1. Write a program to input 5 integers to an array and print the sum of them.

#include <stdio.h>
#include<conio.h>
void main()
{
int i,arr[5],sum=0;
clrscr();
printf("Enter 5 integers of an array :");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
sum=sum+arr[i];
}
printf("sum of all elements of an array =%d",sum);
getch();
}
2. Write a program to input 9 integers to a 3x3 matrix and print transpose of the same.

#include <stdio.h>
#include<conio.h>
void main()
{
int i,j,arr[3][3];
clrscr();
printf("Enter 9 integers of an array :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("\nOriginal matrix is :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
printf("\nIts Transpose matrix is :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",arr[j][i]);
}
printf("\n");
}
getch();
}

Practical Related Theory Questions:

1. Write advantages and disadvantages of arrays.

You might also like