Question

QUESTION 2 Write a program to generate N 20 random number in between 0 to N and [Q2] sort then descending [Q3jand ascending [

it is c++ for question 2 it has multiple parts

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//SNAPSHOTS HAVE BEEN ATTACHED BELOW//


#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>

#define _USE_MATH_DEFINES

using namespace std;

int main()
{
int l=0,n,i,j,temp;
vector <int> random_number;
n=20;//cout<<"Enter value of N: "; cin>>n;
for(i=1;i<=n;i++)
{ random_number.push_back(l+(rand()%20)); }

cout<<"\nRandom numbers are: \n";
for(i=0;i<n;i++)
cout<<random_number[i]<<" , ";

for (i = 0; i < n-1; i++) //BUBBLE SORT
{
for (j = 0; j < n-i-1; j++)
{
if (random_number[j] < random_number[j+1])
{
temp=random_number[j];
random_number[j]=random_number[j+1];
random_number[j+1]=temp;
}
}
}

cout<<"\n\nAfter Sorting in Descending order: \n";
for(i=0;i<n;i++)
cout<<random_number[i]<<" , ";


for (i = 0; i < n-1; i++)
{
for (j = 0; j < n-i-1; j++)
{
if (random_number[j] > random_number[j+1]) // Notice the only change here
{
temp=random_number[j];
random_number[j]=random_number[j+1];
random_number[j+1]=temp;
}
}
}

cout<<"\n\nAfter Sorting in Ascending order: \n";
for(i=0;i<n;i++)
cout<<random_number[i]<<" , ";

//By "sorted evens", I assume the even numbers among the list of random numbers generated earlier.
vector<int> even;
int count=0;

for(i=0;i<n;i++)
{
if(random_number[i]%2==0)
{
count++;
even.push_back(random_number[i]);}
}

cout<<"\n\nSorted even numbers are: \n";
for(i=0;i<count;i++)
cout<<even[i]<<" , ";

//cout<<M_PI; // That's the pi constant.
vector<int> new_range; //new range is 0 to 2*M_PI

cout<<"\n\nNew numbers ranged between (0,2*M_PI) are: \n";
for(i=0;i<count;i++)
{
temp=0+(((even[i]-0)*(2*M_PI-0))/(n-0));
//NewValue =NewMin + (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin))

new_range.push_back(temp);
cout<<new_range[i]<<" , ";
}
cout<<"\n\nSine value of the even numbers ranged between (0,2*M_PI) are: \n";
for(i=0;i<count;i++)
{
cout<<sin(new_range[i])<<" , "; //sin function assumes degree as the unit of parameter
}
cout<<endl;

   return 0;
}

random_number_abc.cpp #include <stdio.h> #include <stdlib.h> #include <bits/stdC++.h> #include <math.h> #include <iostream> & 8 #define _USE_MATH DEFINES using namespace std; 10 11 12 int main() int l=0,n,i,j, temp; vector <int> random_number; n=20;//cout<<"Enter value of N: "; cin>>n; for(i=1;i<=n;i++) { random_number.push_back(l+(rand()%20)); } cout<<"\nRandom numbers are: \n"; for(i=0;i<n;i++) cout<<random_number[i]<<", "; for (i = 0; i < n-1; i++) // BUBBLE SORT for (j = 0; j <n-i-1; j++) if (random number[j] = random number[i+1]), temp=random_number[j]; random_number[j]=random_number[j+1]; random_number[j+1)=temp; cout<<"\n\nAfter Sorting in Descending order: \n"; for(i=0;i<n;i++) cout<<random_number[i]<<", "; for (i = 0; i < n-1; i++) for (j = 0; j < n-i-1; j++) if (random number[j] > random number[j+1]) // Notice the only change here

random_number_abc.cpp TUI (1=;1511;ITTI cout<<random_number[i]<<","; for (i = 0; i<n-1; i++) for (j = 0; j<n-i-1; j++) if (random number[j] > random number[j+1]) // Notice the only change here temp=random_number[j]; random_number[j]=random_number[j+1]; random_number[j+1]=temp; cout<<"\n\nAfter Sorting in Ascending order: \n"; for(i=0;i<n;i++) cout<<random_number[i]<<","; //By "sorted evens", I assume the even numbers among the list of random numbers generated earlier. vector<int> even; int count=0; for(i=0;i<n;i++) if(random_number[i]%2==0) count++; even.push back(random_number[i]); } cout<<"\n\nSorted even numbers are: \n"; for(i=0;i<count;i++) cout<<even[i]<<","; //fout<<M_PI; // That's the pi constant. vector<int> new_range; // new range is to 2*M_PI cout<<"\n\nNew numbers ranged between (0,2*M_PI) are: \n"; for(i=0;i<count;i++) temp=0+(((even[i]-0)*(2*M_PI-O)/(n-0)); //NewValue =NewMin + (((oldValue - OldMin) * (NewMax - Newmin)) / (OldMax - OldMin))

random_number_abc.cpp cout<<"\n\nSorted even numbers are: \n"; for(i=0;i<count;i++) cout<<even[i]<<", "; //cout<<M_PI; // That's the pi constant. vector<int> new_range; // new range is 0 to 2-M_PI cout<<"\n\nNew numbers ranged between (0,2*M_PI) are: in"; for(i=0;i<count;i++) temp=0+(((even[il-)*(2*M PI-O)/In-0). //NewValue =NewMin + ((oldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) new_range.push_back(temp); cout<<new_range[i]<<", "; cout<<"\n\nSine value of the even numbers ranged between (0,2-M_PI) are: \n"; for(i=0;i<count;i++) cout<<sin(new_range[i]]<<","; //sin function assumes degree as the unit of parameter return 0; 95 } 96 C++ - random_number_abc.cpp:75 Random numbers are: 3, 6, 17, 15 , 13, 15, 6, 12, 9, 1, 2, 7, 10, 19, 3, 6, 6, 6, 12, 16, After Sorting in Descending order: 19 , 17 , 16 , 15 , 15 , 13 , 12 , 12, 10, 9, 7, 6, 6, 6, 6, 3, 3, 2, 1, 0, After Sorting in Ascending order: 0, 1, 2, 3, 3, 6, 6, 6, 6, 7, 9, 10, 12, 12, 13, 15, 15, 16, 17, 19, Sorted even numbers are: 0, 2, 6, 6, 6, 6, 10, 12, 12, 16, New numbers ranged between (0,2*M_PI) are: 0,0,1,1,1,1, 3, 3, 3, 5, Sine value of the even numbers ranged between (0,2*MPI) are: 0, 0, 0.841471, 0.841471, 0.841471, 0.841471, 0.14112, 0.14112, 0.14112,-0.958924 [Finished in 1.335s]

Please upvote if it helped you or you have any doubt please comment below

Add a comment
Know the answer?
Add Answer to:
it is c++ for question 2 it has multiple parts QUESTION 2 Write a program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Attach File Browse My Computer Browse Content Collection QUESTION 6 The drum has a weight of...

    Attach File Browse My Computer Browse Content Collection QUESTION 6 The drum has a weight of 100 lb and rests on the floor for which the coefficient of static Friction is us =0.5. If a 3 ft and b 4 ft, determine the smallest magnitude of the force P that will cause impending motion of the drum. FBD 5 points calculation 7 points Final answer 3 points Browse Content Collection Browse My Computer Attach File Save All Answers Click Save...

  • My Grades * Question Completion Status: Tools Save and Submit A Click Submit to complete this...

    My Grades * Question Completion Status: Tools Save and Submit A Click Submit to complete this assessment. << < Question 14 of 14 Question 14 10 points Save Answer 00 n! Σ x" no (2n)! Find the radius of convergence and the interval of convergence for the above series. Write your complete answer (with steps and explanations) to a paper and upload the scan. (You should use "Adobe Scan", just like the midterm) Attach File Browse My Computer Browse Content...

  • Attach File Browse My Computer Browse Content Collection Browse Dropbox Save Answer QUESTION 5 5 points...

    Attach File Browse My Computer Browse Content Collection Browse Dropbox Save Answer QUESTION 5 5 points (Extra Credit) This is a bonus question, but it is also good practice for IR Spectroscopy. It wouldn't hurt to give it a try :) Imagine that you conducted the reduction of benzophenone in class and proceeded to take the IR of your materials. You know that you can observe the success of a reaction by using Infrared Spectroscopy (IR) and comparing the spectra...

  • 10 points Save Answer Find Fourier Cosine series of f(x) = sinx on (0,7). Attach File...

    10 points Save Answer Find Fourier Cosine series of f(x) = sinx on (0,7). Attach File Browse My Computer for Copyright eared File Browse Content Collection Click Submit to complete this assessment Question 3 of 3

  • Tommy Wait, a minor league baseball pitcher, is notorious for taking an excessive amount of time...

    Tommy Wait, a minor league baseball pitcher, is notorious for taking an excessive amount of time between pitches. In fact, his times between pitches are normally distributed with a mean of 32 seconds and a standard deviation of 2.8 seconds. What percentage of his times between pitches are longer than 36 seconds? Round to the nearest percent. Attach File Browse My Computer Browse Content Collection Browse Dropbox Browse Content Collection QUESTION 3 The times that college students spend studying per...

  • 0.2 points Save Answer QUESTION 1 Draw the mechanism for the reaction of 3,3-dimethylbutanal in the...

    0.2 points Save Answer QUESTION 1 Draw the mechanism for the reaction of 3,3-dimethylbutanal in the presence of EtOK/EIOH. Submit a file showing the steps Attach File Browse My Computer Browse Content Collection 0.2 points Save Answer QUESTION 2 Is the reaction between acetone and ethylbromide in the presence of MeONa/MeOH substitution or addition? substitution addition 0.2 points Save Answer QUESTION 3 To do an enolate reaction you need alpha-protons beta-protoHS alpha-carbon beta-carbon 0.2 points Save Answer QUESTION 4 What...

  • Let x denote the time it takes to run a road race. Suppose x is approximately...

    Let x denote the time it takes to run a road race. Suppose x is approximately normally distributed with a mean of 195 minutes and a standard deviation of 24 minutes. If one runner is selected at random, what is the probability that this runner will complete this road race in less than 187 minutes? Round your answer to four decimal places. Attach File Browse My Computer Browse Dropbox Browse Content Collection QUESTION 5 The GPAs of all students enrolled...

  • The times that college students spend studying per week have a distribution skewed to the right...

    The times that college students spend studying per week have a distribution skewed to the right with a mean of 8.6 hours and a standard deviation of 2.8 hours. Find the probability that the mean time spent studying per week for a random sample of 16 college students would be more than 9.1 hours. Round your answer to two decimal places. Attach File Browse My Computer Browse Content Collection Browse Dropbox QUESTION 7 The GPAs of all students enrolled at...

  • UIT WIuld mean of 3.05 and a standard deviation of 0.30. Find the probability that the...

    UIT WIuld mean of 3.05 and a standard deviation of 0.30. Find the probability that the mean GPA of a random sample of 49 students selected from this university is 2.75 or lower, Round your answer to four decimal places Attach File Browse My Computer Browse Content Collection Browse Dropbox QUESTION 6 The times that college students spend studying per week have a distribution skewed to the right with a mean of 8.6 hours and a standard deviation of 2.8...

  • LUULIS spend scuoying per week have a distribution skewed to the right with a mean of...

    LUULIS spend scuoying per week have a distribution skewed to the right with a mean of 8.6 hours and a standard deviation of 28 houm Find the probability that the mean time spent studying per week for a random sample of 49 college students would be between 8.2 and 8.9 hours. Round your answer to two decimal places. Attach File Browse My Computer Browse Content Collection Browse Dropbox QUESTION 4 Let x denote the time it takes to run a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT