Easy68k Help! Please answer if possible. Thank you Question 1: (50 pts.) Initial
ID: 3572376 • Letter: E
Question
Easy68k Help!
Please answer if possible. Thank you
Question 1: (50 pts.)
Initialize an array [14, 7, 1, 17, 10]. Then,
Print it out. (20 pts.)
Use loop(s) to find out the greatest and least numbers in this array and print them out on two lines. (30 pts.)
Desired output:
14 7 1 17 10
Question 2: (50 pts.)
Initialize an array [1, 7, 13, 0, 11, 24, 8]. Then,
Load a signed number from the keyboard. (20 pts.)
If the number is negative, print out odd elements in the array. Otherwise, print out even elements. Do not forget the commas. (30 pts.)
Desired output:
1, 7, 13, 11
Or:
0, 24, 8
Question 3: (60 pts.)
Initialize an array [3, -1, 0, 4]. Then, print out these elements in ascending order.
Desired output:
-1 0 3 4
Explanation / Answer
Solution for QUESTION 1:
int main()
{
int array[]=[14, 7, 1, 17, 10];
int smallest, largest,j;
for (int i=0;i<5;i++)
{
cout<<array[i];
}
smallest=array[0];
largest=array[0];
for(j=0;j<5;j++)
{
if(array[i]<smallest) {
smallest=a[i];
else
largest=a[i];
}
}
cout<<”largest number:”<<largest;
cout<<”smallest number:”<<smallest;
}
int main()
{
int array[]=[14, 7, 1, 17, 10];
int smallest, largest,j;
for (int i=0;i<5;i++)
{
cout<<array[i];
}
smallest=array[0];
largest=array[0];
for(j=0;j<5;j++)
{
if(array[i]<smallest) {
smallest=a[i];
else
largest=a[i];
}
}
cout<<”largest number:”<<largest;
cout<<”smallest number:”<<smallest;
}
The solution for QUESTION 2 is:
int main()
{
int array=[1, 7, 13, 0, 11, 24, 8];
int n;
cout<<”enter a signed number”;
cin>>n;
if(n<0)
{
cout<<”the even numbers in the array are:”
for(int i=0;i<7;i++)
{
if(array[i]%2==0)
cout<<array[i]<<”,”;
}
}
else
cout<<”the odd numbers in the array are:”
for(int i=0;i<7;i++){
if(array[i] %2 !=0)
cout<<array[i]<<”,”;
}
}
The solution for QUESTION 3 is as follows:
int main()
{
int array= [3, -1, 0, 4];
int temp;
for(int i=0;i<=4;i++)
{
for(int j=0;j<=4-i;j++)
{
if(array[j]>array[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<" Data after sorting: ";
for(j=0;j<10;j++)
{
cout<<a[j];
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.