Professional Documents
Culture Documents
int main()
{
int i, n, arr[10];
return 0;
}
Output
Enter total number of elements(1 to 10): 8
Enter Number 1: 23
Enter Number 3: 50
Enter Number 4: 33
Enter Number 5: 55
Enter Number 6: 43
Enter Number 7: 5
Largest element = 55
return (0);
}
Output
Enter no of elements : 5
11 44 22 55 99
Smallest Element : 11
if(j==1)
printf("\n");
}
}
return 0;
}
Ouput
Enter a[1][1]: 2;
Enter a[1][2]: 5;
Enter a[2][1]: 1;
Enter a[2][2]: 2;
Enter b[1][1]: 2;
Enter b[1][2]: 0;
Enter b[2][2]: 5;
Sum Of Matrix:
4 5
24 7
• Transpose of a matrix
#include <stdio.h>
int main()
{
int a[10][10], transpose[10][10], r, c, i, j;
printf("Enter rows and columns of matrix: ");
scanf("%d %d", &r, &c);
return 0;
}
Output
Entered Matrix:
2 3 4
5 6 4
Transpose of Matrix:
2 5
3 6
4 4
#include<stdio.h>
#include<math.h>
int main ()
{
int arr[5][5];
int i, j, normal, trace = 0, rows, columns, sum = 0, temp = 0;
printf("\nEnter Number of Rows of Matrix:\t");
scanf("%d", &rows);
printf("\nEnter Number of Rows of Matrix:\t");
scanf("%d", &columns);
printf("\nEnter the Elements of Matrix:\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j < columns; j++)
{
scanf("%d", &arr[i][j]);
}
}
for(i = 0; i < rows; i++)
{
for(j = 0; j < columns; j++)
{
temp = arr[i][j] * arr[i][j];
sum = sum + temp;
}
}
normal = sqrt(sum);
printf("\nThe Matrix\n");
for(i = 0; i < rows; i++)
{
for(j = 0; j< columns; j++)
{
printf("%d\t", arr[i][j]);
}
printf("\n");
}
for(i = 0; i < rows; i++)
{
trace = trace + arr[i][i];
}
printf("\nTrace of Matrix:\t%d\n", trace);
printf("\nNormal of Matrix:\t%d\n", normal);
return 0;
}
• Sorting using bubble sort
Bubble Sort algorithm
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements
if they are in wrong order.
Example:
First Pass:
( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.
( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does
not swap them.
Second Pass:
( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm
needs one whole pass without any swap to know it is sorted.
Third Pass:
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
int main()
{
int array[100], n, c, d, swap;
return 0;
}