have to write a program using array that asks the user to input any 10 numbers the program than sorts the numbers in ascending order and displays the sorted numbers, kindly help
have to write a program using array that asks the user to input any 10 numbers the program than sorts the numbers in ascending order and displays the sorted numbers, kindly help
How far have you got? Do you know what an array is?
What is an Array?
An Array is a group of data of int (integer) type. In other words, you can use an array to store multiple integers in a single variable array without declearing multiple variable.
For Example, To take 5 integers as input we initialize them as:
int n1,n2,n3,n4,n5;
Here with the help of array we can store all those numbers in one array
int array[5] /*Where 5 Showns the no of integers it can store*/
How to use Array?
Here's a simple program that takes 5 integers in a array.
#include<stdio.h>
#include<conio.h>
main(){
int array[5];
for(int i=0;i<5;i++){
printf("Enter a no = "); //it will ask to input you number 5 times because of loop
scanf("%d",&array[i]); //it will store values of no in array
}
for(i=0;i<5;i++){
printf("\nValue Store in array[%d] is %d\n",i+1,array[i]);
}
getche();
}
I Hope that answer's your query :)
-Syed
If you're looking for a program that Takes 10 Integers in an array and display's them in assending order then here's the progarm in Turbo C
#include <stdio.h>
void main()
{
int i, j, a, number[10];
for (i = 0; i < 10; ++i){
printf("Enter Number %d =",i+1);
scanf("%d", &number[i]); }
for (i = 0; i < 10; ++i){
for (j = i + 1; j < 10; ++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 < 10; ++i){
printf("%d\n", number[i]);
}
}
H[o]pe that helps ;)
@ Fosterzone An array isn't just for int's. All an array is is a group of elements that all have the same type. each element is differentiated by a unique identifier (index). You can think of an array as a cubbyhole. The array has a number of spots equal to the size of the array and the size of each hole is big enough to store the data type that the array is declared for.