0% found this document useful (0 votes)
65 views18 pages

Module 3 Arrays

This document discusses arrays in C programming. It defines arrays as collections of homogeneous elements stored in consecutive memory locations that can be referred to using the same name. There are two types of arrays: one-dimensional and two-dimensional. The document explains how to declare, initialize, and access elements of one-dimensional and two-dimensional arrays. It also provides examples of C programs that demonstrate reading and printing array elements, reversing an array, calculating sum and average of elements, and calculating sum of odd and even elements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
65 views18 pages

Module 3 Arrays

This document discusses arrays in C programming. It defines arrays as collections of homogeneous elements stored in consecutive memory locations that can be referred to using the same name. There are two types of arrays: one-dimensional and two-dimensional. The document explains how to declare, initialize, and access elements of one-dimensional and two-dimensional arrays. It also provides examples of C programs that demonstrate reading and printing array elements, reversing an array, calculating sum and average of elements, and calculating sum of odd and even elements.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 18

C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

MODULE 3
CHAPTER 1: ARRAYS
1. What is an array? List the types of array. Explain the declaration and initialization of
one dimensional arrays.

 Definition: An array is a collection of homogeneous elements(same type of elements)


which are stored in consecutive memory location and referred by using the same name.
 Use of an array : Generally a variable can hold a single value of specified datatype, but
to store the set of values of same datatype ,the variable cannot be used. Hence the arrays
are used for this purpose.
 There are two types of arrays:
1. One dimensional array
2. Two dimensional array

Note : Each value in the array is referred by a same name and the index indicates the position of
elements in the array the index is a positive integer number which has to be enclosed in pair of
square brackets[ ].

One dimensional array(1-D) :


It is a linear list of values of the same datatype. It has only one index, the index value always
starts from zero and ends at one less than size of the array.

The 1-D array resembles row matrix or column matrix.

Declaration :

Syntax :

Datatype arrayname[size];
Where,

Datatype represents the type of elements stored in an array.


Array name represents the name used to access each array elements.
Size represents number of elements to be stored in an array.

Example : int a[6];

Once the datatype of the array and size of the array are known we can use the following formula
to calculate memory required for the given array.

Required memory size = (size of the array) *( size of data type)

For the given example the required memory is


Size of array*size(int)
6*2=12bytes

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 1


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

Initialization :

Once the declaration of array is over, we can initialize the array elements either statically or
dynamically.

i. Static initialization :

we can initialize the elements statically using assignment operator(=) as follows:

Method 1 : we can initialize all the elements of the arrays in a single c-statement by grouping
them within the pair of { }.

Syntax : type array_name[size] = {value1,value2,.....valuen };


Example : int a[6] = {10,20,30,40,50,60};

Method 2 : we can initialize the array elements one by one with the reference of index values.

Syntax : array_name[index]=value;

Example : a[0] = 10;


a[1] = 20;
a[2] = 30;
a[3] = 40;
a[4] = 50;
a[5] = 60;

ii. Dynamic initialization:

Method 1: we can initialize the array elements dynamically using the multiple scanf( )
statements as follows :

scanf(“%d”,&a[0]);
scanf(“%d”,&a[1]);
scanf(“%d”,&a[2]);
scanf(“%d”,&a[3]);
scanf(“%d”,&a[4]);
scanf(“%d”,&a[5]);

Method 2: we can initialize array elements dynamically one by one using for loop followed by
scanf( ) statement, so that we can avoid having multiple scanf( ) statements to initialize the
array elements separately in the program.

Example : int a[6];


for(=0;i<=5;i++)
scanf(“%d”,&a[i]);

To display the array elements in the output we should use for loop followed by printf( )
statements.

Example : int a[6] = {10,20,30,40,50,60};

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 2


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

for(=0;i<=5;i++)
printf/(“%d\n”,a[i]);

TWO dimensional array(2-D) :


 Declaration:
Syntax :

datatype array_name[size1][size2];

Where,
datatype represents type of elements to be inserted for 2-D array.
Array_name represents the name used to refer elements of the array.
Size1 represents number of rows.
Size2 represents number of columns.

Example : int a[2][3];


Note : to calculate the total amount of memory required for the 2-D array of given size
we should evaluate the following equation.
Total size = size of datatype*number of rows*number of columns
OR
Total size = size of datatype*size1*size2

For the given example the required memory is


= 2*2*3
=12 bytes

 Initialization:

i. Static initialization:
Method 1 : we can initialize the 2D array statically using assignment operator(=) and by
grouping all the values within the pair of flower braces as shown in the syntax.

Syntax :
datatype array_name[size1][size2] = {value list};

Example : int a[2][3] = {12,13,14,15,16,17};

Method 2 : As a programmer we can separate the elements of each row by listing them
within the separate pair of flower braces[nested braces].

Example : int a[2][3] = {{12,13,14}{15,16,17}};

Method 3 : the array elements can also be initialize individually by accessing them in the
index value.

Example : int a[2][3];

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 3


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

int a[0][0]=12;
int a[0][1]=13;
int a[0][2]=14;
int a[1][0]=15;
int a[1][1]=16;
int a[1][2]=17;

ii. Dynamic initialization :


Method 1: we can also initialize array elements dynamically during the run
time(execution time) using scanf( ).
Example : scanf(“%d”,&a[0][0]);
scanf(“%d”,&a[0][1]);
scanf(“%d”,&a[0][2]);

Method 2: In order to reduce the multiple scanf( ) statements, we can use the nested for
loop followed by the scanf statement which has to be executed repeatedly to initialize all
the elements of the 2D array row by row.

Example :
int a[2][3];
for(i=0;i<=1;i++)
{
for(j=0;j<=2:j++)
scanf(“%d”,&a[i][j]);
}

We can display the array elements using nested for loop followed by printf( )
statement.
for(i=0;i<=1;i++)
{
for(j=0;j<=2:j++)
printf(“%d\n”,a[i][j]);
}

Example Programs(1-D arrays) :


1. Write a c program to read and display the array elements of given size.
#include<stdio.h>
void main()
{
int n,i,a[50];
clrscr();
printf(“enter the value of n”);
scanf(“%d”,&n);
printf(“enter the %d elements for the list\n”,n);
for(i=0;i<=n-1;i++)
scanf(“%d”,&a[i]);
printf(“the elements in the list are\n”);

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 4


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

for(i=0;i<=n-1;i++)
printf(“%d\n”,a[i]);
getch();
}

2. Write a c program to read and display the array elements of given size and display
them in reverse order.
#include<stdio.h>
void main()
{
int n,i,a[50];
clrscr();
printf(“enter the value of n”);
scanf(“%d”,&n);
printf(“enter the %d elements for the list\n”,n);
for(i=0;i<=n-1;i++)
scanf(“%d”,&a[i]);
printf(“the elements in the list are\n”);
for(i=n-1;i>=0;i--)
printf(“%d\n”,a[i]);
getch();
}

3. Write a c program to compute sum and average of array elements of the given size.
#include<stdio.h>
void main()
{
int n,i,a[50], sum=0;
float avg;
clrscr();
printf(“enter the value of n”);
scanf(“%d”,&n);
printf(“enter the %d elements for the list\n”,n);
for(i=0;i<=n-1;i++)
{
scanf(“%d”,&a[i]);

}
for(i=0;i<=n-1;i++)
{
sum=sum+a[i];
}
printf(“sum=%d\n”,sum);
avg=(float)sum/n;
printf(“average of elements in the list=%f”,avg);
getch();
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 5


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

4. Write a c program to compute sum of odd numbers and even numbers in the given list
and also compute average of all the elements in the list.
#include<stdio.h>
void main()
{
int n,i,a[50], even_sum=0,odd_sum=0;
float avg;

printf(“enter the value of n”);


scanf(“%d”,&n);
printf(“enter the %d elements for the list\n”,n);
for(i=0;i<=n-1;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<=n-1;i++)
{
if(a[i]%2==0)
even_sum=even_sum+a[i];
else
odd_sum=odd_sum+a[i];
}
Printf(“sum of all even numbers=%d”,even_sum);
Printf(“sum of all odd numbers=%d”,odd_sum);
avg = (float)(even_sum+odd_sum)/n;
printf(“average of elements in the list=%f”,avg);

5. Write a c program which takes the marks of n students as input and find the maximum
marks in the class.
#include<stdio.h>
void main()
{
int n,marks[50],max,i;
printf(“enter number of students\n”);
scanf(“%d”,&n);
printf(“enter the marks of %d students”,n);
for(i=0;i<=n-1;i++)
scanf(”%d”,&marks[i]);
max=marks[0];
for(i=0;i<=n-1;i++)
{
if(marks[i]>max)
max=marks[i];
}
Printf(“the maximum marks=%d”,max);
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 6


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

6. Write a c program find the maximum element in the list of elements.


#include<stdio.h>
void main()
{
int n,a[50],max,i;

printf(“enter number of students\n”);


scanf(“%d”,&n);
printf(“enter the marks of %d students”,n);
for(i=0;i<=n-1;i++)
scanf(”%d”,&a[i]);
max=a[0];
for(i=0;i<=n-1;i++)
{
if(a[i]>max)
max=a[i];
}
Printf(“the maximum marks=%d”,max);

7. Write a c program which accepts n integer values as an input and find the minimum
element in the list.
#include<stdio.h>
void main()
{
int n,marks[50],max,i;

printf(“enter number of students\n”);


scanf(“%d”,&n);
printf(“enter the marks of %d students”,n);
for(i=0;i<=n-1;i++)
scanf(”%d”,&marks[i]);
min=marks[0];
for(i=0;i<=n-1;i++)
{
if(marks[i]<min)
min=marks[i];
}
Printf(“the minimum marks=%d”,min);

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 7


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

8. Write a c program to search for a key element in given list(using linear search).

#include<stdio.h>
void main()
{
int n,a[50],key,i;
clrscr();
printf(“enter number of elements\n”);
scanf(“%d”,&n);
printf(“enter the elements”,n);
for(i=0;i<=n-1;i++)
scanf(”%d”,&a[i]);
Printf(“enter key element to search\n”);
scanf(”%d”,&key);
for(i=0;i<=n-1;i++)
{
if(key==a[i])
{
Printf(“key element found at %d”,i+1);
getch( );
exit(0);
}
}
Printf(“key not found”);
getch();
}

9. Write a c program to search for a key element in given list(binary search technique).
#include<stdio.h>
void main()
{
int n,a[50],key,i,low,high,mid;
clrscr();
printf(“enter number of elements\n”);
scanf(“%d”,&n);
printf(“enter the elements”,n);
for(i=0;i<=n-1;i++)
scanf(”%d”,&a[i]);
Printf(“enter key element to search\n”);
scanf(”%d”,&key);
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]) == key)
{
printf("\nkey is found at location %d\n",mid+1);

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 8


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

getch( );
exit(0);
}
if(key<a[mid] )
{
high=mid-1;
low=low;
}
else
{
low=mid+1;
high=high;
}
}
printf("name not found in the list");
getch();
}

10. Write a c program to generate Fibonacci series using array.


#include<stdio.h>
void main()
{
int n,fib[50],i;
clrscr();
printf(“enter number of elements to be generated in series”);
scanf(“%d”,&n);
fib[0]=0;
fib[1]=1;
if(n==1)
printf(“%d”,fib[0]);
else if(n==2)
printf(“%d\t%d”,fib[0],fib[1]);
else
for(i=2;i<=n-1;i++)
{
fib[i]=fib[i-1]+fib[i-2];
printf(“%d”,fib[i]);
}
getch();
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 9


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

11. Design, develop and execute a program in C to evaluate the given polynomial f(x) =
a4x 4 + a3x 3 + a2x 2 + a1x + a0 for given value of x and the coefficients using Horner’s
method.
#include<stdio.h>
void main()
{
int a[100],sum=0,x,n,i;
clrscr();
printf("Enter the degree of the polynomial:\n");
scanf("%d",&n);
printf("Enter %d coefficients into array:\n",n+1);
for(i=0;i<=n;i++)
scanf("%f",&a[i]);
printf("Enter value of x:\n");
scanf("%d",&x);
sum=a[n]*x;
for(i=n-1;i>0;i--)
{
sum=(sum+a[i])*x;
}
sum=sum+a[0];
printf("The sum of polynomial = %.d\n",sum);
getch();
}

12. Develop an algorithm ,implement and execute a C program that reads N


integer numbers and arrange them in ascending order using bubble sort
technique.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,temp,a[100];
clrscr();
printf("Enter the value for n:\n");
scanf("%d",&n);
printf("Enter %d elements into array:\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);

printf("The original elements are:\n");


for(i=0;i<n;i++)
printf("%d\t",a[i]);

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 10


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

for(i=1;i<n;i++)
{
for(j=0 ; j< n-i ; j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}

printf("\nThe sorted array is:\n");


for(i=0;i<n;i++)
printf("%d\t",a[i]);

getch();
}

13. Develop an algorithm ,implement and execute a C program that reads N


integer numbers and arrange them in ascending order using selection sort
technique.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,temp,a[100];
clrscr();
printf("Enter the value for n:\n");
scanf("%d",&n);
printf("Enter %d elements into array:\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);

printf("The original elements are:\n");


for(i=0;i<n;i++)
printf("%d\t",a[i]);

for(i=0;i<n;i++)
{
for(j=i+1 ; j< n-i ; j++)
if(a[i]>a[j])
{
temp=a[i];

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 11


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

a[i]=a[j];
a[j]=temp;
}
}

printf("\nThe sorted array is:\n");


for(i=0;i<n;i++)
printf("%d\t",a[i]);

getch();
}

Example programs(2-D arrays):


1. Write a c program to read and display the elements of 2D array of a given size.
#include<stdio.h>
void main()
{
int i,j,m,n,a[20][20];
clrscr();
printf(“enter the order of matrix”);
scanf(“%d%d”,&m,&n);
printf(“enter the elements for matrix\n”);
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf(“%d”,&a[i][j]);
}
Printf(“elements of matrix are:\n”);
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
printf(“%d\t”,a[i][j]);
}
Printf(“\n”);
getch();
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 12


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

2. Write a c program to compute transpose of a given matrix.


#include<stdio.h>
void main()
{
int i,j,m,n,a[20][20],b[20][20];
clrscr();
printf(“enter the order of matrix”);
scanf(“%d%d”,&m,&n);
printf(“enter the elements for matrix\n”);
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf(“%d”,&a[i][j]);
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
b[j][i]=a[i][j];
}
Printf(“elements of matrix are:\n”);
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
printf(“%d\t”,b[i][j]);
}
Printf(“\n”);
getch();
}

3. Write a C program to perform the addition of any two matrices of the given
order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],b[50][50],c[50][50];
int m,n,i,j;
clrscr();
printf("enter the order of the matrix\n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix A\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&a[i][j]);
}
printf("enter the elements of matrix B\n");
for(i=0;i<=m-1;i++)

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 13


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

{
for(j=0;j<=n-1;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
printf("Matrix A\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Matrix B\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("Matrix C\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 14


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

4. Write a C program to multiply two matrices of the given size[lab program].


#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50],b[50][50],c[50][50];
int m,n,i,j;
clrscr();
printf("enter the order of the matrix A\n");
scanf("%d%d",&m,&n);
printf("enter the order of the matrix B\n");
scanf("%d%d",&p,&q);
if(n!=p || m!=q)
{
printf("matrix multiplication not possible\n");
getch();
exit(0);
}
printf("enter the elements of matrix A\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("enter the elements of matrix A\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++){
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]+=a[i][k]*b[k][j];
}
}
printf("Matrix A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Matrix B\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
printf("%d\t",b[i][j]);
printf("\n");
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 15


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

printf("Matrix C\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
getch( );
}

5. Write a c program find the maximum element in the table/matrix/2D array of


elements.
#include<stdio.h>
void main()
{
int m,n,a[50][50],max,i,j;
clrscr( );
printf(“enter order of matrix\n”);
scanf(“%d%d”,&m,&n);
printf(“enter elements of matrix”);

for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
scanf(”%d”,&a[i][j]);
max=a[0][0];
for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
{
if(a[i][j]>max)
max=a[i][j];
}
Printf(“the maximum element=%d”,max);
getch( );
}

6. Write a C program to perform the addition of principle diagonal elements any


matrix of the given order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50], sum=0;
int m,n,i,j;
clrscr();
printf("enter the order of the matrix\n");
scanf("%d%d",&m,&n);

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 16


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

if(m!=n){
printf(“matrix is not square matrix”);
exit(0);
}
printf("enter the elements of matrix A\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(i==j)
sum=sum+a[i][j];
}

printf("sum of principle diagnol elements=%d\n",sum);


}
getch( );
}

7. Write a C program to perform the addition of upper triangular elements any


matrix of the given order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50], sum=0;
int m,n,i,j;
clrscr();
printf("enter the order of the matrix\n");
scanf("%d%d",&m,&n);

if(m!=n){
printf(“matrix is not square matrix”);
exit(0);
}
printf("enter the elements of matrix A\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<=m-1;i++)

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 17


C PROGRAMMING FOR PROBLEM SOLVING[18CPS13/23] Arrays

{
for(j=0;j<=n-1;j++)
{
if(i>=j)
sum=sum+a[i][j];
}

printf("sum of upper triangular elements=%d\n",sum);


}
getch( );
}

8. Write a C program to perform the addition of lower triangular elements any


matrix of the given order.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50][50], sum=0;
int m,n,i,j;
clrscr();
printf("enter the order of the matrix\n");
scanf("%d%d",&m,&n);

if(m!=n){
printf(“matrix is not square matrix”);
exit(0);
}
printf("enter the elements of matrix A\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
if(i<=j)
sum=sum+a[i][j];
}

printf("sum of lower triangular elements=%d\n",sum);


}
getch( );
}

Dept of CSE/ISE,SJCIT BY: Mr. PRADEEPKUMAR G M, ASST.PROF Page 18

You might also like