1.c++ array declaration: string names[500]; Assume array is filled with values.
ID: 3836176 • Letter: 1
Question
1.c++ array declaration: string names[500]; Assume array is filled with values. Wriite the code that checks to see if the array is in alphabetical order (first is smaller yhan second, second smaller than third...) 1.c++ array declaration: string names[500]; Assume array is filled with values. Wriite the code that checks to see if the array is in alphabetical order (first is smaller yhan second, second smaller than third...) Assume array is filled with values. Wriite the code that checks to see if the array is in alphabetical order (first is smaller yhan second, second smaller than third...)Explanation / Answer
The code you asked in the question is nothing but an sorting code and it is given below :
#include<iostream.h>
#include<conio.h>
void main()
{
int i,a[500],temp,j;
clrscr();
cout<<"Enter any num in array : ";
for(i=0;i<=500;i++)
{
cin>>a[i];
}
cout<<" Data before inserting: ";
for(j=0;j<500;j++)
{
cout<<a[j];
}
for(i=0;i<=500;i++)
{
for(j=0;j<=500-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<" Data after checking the array values: ";
for(j=499;j>=0 ;j--)
{
cout<<a[j];
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.