C++ programming (Problem 1) Create a program to sort numbers or letters. 1. It i
ID: 3573352 • Letter: C
Question
C++ programming
(Problem 1)
Create a program to sort numbers or letters.
1. It is a program that can sort input contents from user in ascending order regardless of number (int or float) or character (char).
2. The main function only accepts inputs and completes the program through the sort and output functions.
3. We do not care about the order of numbers or characters of the same size.
4. The following is an example of running the program:
Data items in original order
> 6 4 8 10 12 89 68 45 37
Data items in ascending order
> 4 6 8 10 12 37 45 68 89
Data items in original order
> 5.2 36.5 3.4 12.8 1.9 6.8 24.3
Data items in ascending order
> 1.9 3.4 5.2 6.8 12.8 24.3 36.5
Data items in original order
> I n h a U n i v .
Data items in ascending order
> . I U a h i n n v
Data items in original order
> 6 4 8 10 12 89 68 45 37
Data items in ascending order
> 4 6 8 10 12 37 45 68 89
Data items in original order
> 5.2 36.5 3.4 12.8 1.9 6.8 24.3
Data items in ascending order
> 1.9 3.4 5.2 6.8 12.8 24.3 36.5
Data items in original order
> I n h a U n i v .
Data items in ascending order
> . I U a h i n n v
Explanation / Answer
#include<conio.h>
#include<iostream.h>
void main()
{
float i,a[10],temp,j;
clrscr();
cout<<"Enter numbers in array: ";
for(i=0;i<=9;i++)
{
cin>>a[i];
}
cout<<" Data items in orginal order: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
for(i=0;i<=10;i++)
{
for(j=0;j<=10-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<" Data items in ascending order: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.