array in c programming(part3)
1.write a c program to input 10 numbers and arrange the numbers in ascending order.
#include<stdio.h>
{
int i, j, a, n, number[50];
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in ascending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);
}
Enter the value of n:10
Enter the numbers 5
6
4
2
4
3
1
8
9
7
1
The numbers arranged in ascending order are given below
1
1
2
3
4
4
6
7
8
9
2.write a c program to input 10 numbers and arrange them in descending order
#include<stdio.h>
{
int i, j, a, n, number[50];
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The numbers arranged in descending order are given below \n");
for (i = 0; i < n; ++i)
printf("%d\n", number[i]);
}
3.write a c program to input 10 numbers and find the smallest number
#include<stdio.h>
{
int i, j, a, n, number[50];
printf("Enter the value of N \n");
scanf("%d", &n);
printf("Enter the numbers \n");
for (i = 0; i < n; ++i)
scanf("%d", &number[i]);
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
printf("The smallest number is \n");
printf("%d\n", number[10]);
}
Comments
Post a Comment