0% found this document useful (0 votes)
44 views

Array

The document discusses operations that can be performed on 1D and 2D arrays in C programming language. For 1D arrays, it lists finding the largest element, searching for an item, bubble sort, finding the largest two elements, and inserting or deleting an item. For 2D arrays, it provides code examples to multiply two matrices, find the sum of diagonal elements, increment the diagonal elements by 1, and replace the diagonal elements with 0. It also mentions summing the digits of a number and checking if a number is a palindrome.

Uploaded by

Sunita Sapkota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Array

The document discusses operations that can be performed on 1D and 2D arrays in C programming language. For 1D arrays, it lists finding the largest element, searching for an item, bubble sort, finding the largest two elements, and inserting or deleting an item. For 2D arrays, it provides code examples to multiply two matrices, find the sum of diagonal elements, increment the diagonal elements by 1, and replace the diagonal elements with 0. It also mentions summing the digits of a number and checking if a number is a palindrome.

Uploaded by

Sunita Sapkota
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1 D ARRAY:

1.To find the largest element in an array. 2. to search a particular item in an array. 3. bubble sort. 4. to find the largest and second largest element in an array. 5. insert an item at a particular location. 6 delete an item from a particular location.

2 D ARRAY: 1.Multiplication of two matrics


#include<stdio.h> #include<conio.h> void main( ) { Int a[3][3],b[3][3],c[3][3],i,j,k; printf(\n enter the elements of first matrics:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { scanf(%d,&a[i][j]); } } printf(\n enter the elements of second matrics:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { scanf(%d,&b[i][j]); } } for(i=0;i<3;i++) {

for( j= 0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { C[i][j] = c[i][j]+a[i][k]*b[k][j]; } } } printf(\n Multiplication of two matrics is:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { printf( %d,c[i][j]); } printf(\n); } getch(); }

2. Write a program to print the sum of diagonal elements of 2D array.


#include<stdio.h> #include<conio.h> void main( ) { Int a[3][3],i,j,sum=0; printf(\n enter the elements of matrics:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { scanf(%d,&a[i][j]); } } for(i=0;i<3;i++) { for( j= 0;j<3;j++) {

if( i == j || i+j=2) { sum = sum+a[i][j]; } } } printf(\n Sum of diagonal elements is %d,sum); getch(); }

3. Write a program to increment each diagonal elements of 2D array by 1.


#include<stdio.h> #include<conio.h> void main( ) { Int a[3][3],i,j; printf(\n enter the elements of matrics:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { scanf(%d,&a[i][j]); } } for(i=0;i<3;i++) { for( j= 0;j<3;j++) { if( i == j || i+j=2) { a[i][j] = a[i][j]+1; } } } printf(\n matrics after increment is :\n);

for(i=0;i<3;i++) { for( j= 0;j<3;j++) { printf( %d,&a[i][j]); } printf(\n); } getch(); }

4. Write a program to replacing each diagonal elements of 2D array by 0.


#include<stdio.h> #include<conio.h> void main( ) { Int a[3][3],i,j; printf(\n enter the elements of matrics:\n) for(i=0;i<3;i++) { for( j= 0;j<3;j++) { scanf(%d,&a[i][j]); } } for(i=0;i<3;i++) { for( j= 0;j<3;j++) { if( i == j || i+j=2) { a[i][j] = 0; } } }

printf(\n matrics after placing 0 is :\n); for(i=0;i<3;i++) { for( j= 0;j<3;j++) { printf( %d,a[i][j]); } printf(\n); } getch(); }

SUM OF DIGITS OF A NUMBER. CHECK A NUMBER IS PALINDROME OR NOT

You might also like