SOURCE CODE:
#include #include void main()
{
int array[100], n, c, d, swap; printf("Enter number of elements\n"); scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++) scanf("%d", &array[c]); for (c = 0 ; c < n - 1; c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d]; array[d] = array[d+1]; array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order:\n"); for (c = 0; c < n; c++)
printf("%d\n", array[c]); getch();
}------------------------------*-----------OUTPUT----------------*------------------------
Matrix Addition/ Subtraction ALGORITHM:
Step 1: Start.
Step 2: declare m, n, I, j, a[10][10], b[10][10], c[10][10] Step 3: print enter size of matrix
Step 4: read m, n.
Step 5: print enter the values into the first matrix Step 6: repeat step until i less than m and j less than n
read a[i][j]
Step 7: print entered matrix is
Step 8: repeat step until i less than m and j less than n Print a[i][j]
Step 9: print enter the values into second matrix
Step 10: repeat step until i less than m and j less than n read b[i][j]
Step 11: print entered matrix is
Step 12: repeat step until i less than m and j less than n print b[i][j]
Step 13: repeat step until i less than m and j less than n Step 14: c[i][j] ← a[i][j]+b[i][j]
Step 15: print resultant matrix after addition is
Step 16: repeat step until i less than m and j less than n Step 17: print c[i][j]
Step 18: Stop.
SOURCE CODE:
#include #include int main()
{
Int m,n, i, j;
int a[10][10],b[10][10],c[10][10];
printf("Enter the size of the matrix \n"); scanf("%d%d",&m, &n);
printf("enter the values into the first matrix \n"); for(i=0;i{
for(j=0;j{
scanf("%d", &a[i][j]);
}
}
printf("The matrix entered is \n");
for(i=0;i
{
for(j=0;j{
printf("%d ", a[i][j]);
}
printf("\n");
}
printf("enter the values into the second matrix \n"); for(i=0;i
{
for(j=0;j{
scanf("%d", &b[i][j]);
}
}
printf("The matrix entered is \n");
for(i=0;i
{
for(j=0;j{
printf("%d ", b[i][j]);
}
printf("\n");
}
//matrix addition
for(i=0;i
{
for(j=0;j{
c[i][j] = a[i][j]+b[i][j];
}
}
printf("The resultant matrix after addition is \n");
for(i=0;i
{
for(j=0;j{
printf("%d ", c[i][j]);
}
printf("\n");
}
getch();
}
------------------------------*-----------OUTPUT----------------*------------------------
Do'stlaringiz bilan baham: |