using c Practicing reference parameters and generating rando

using c++

Practicing reference parameters and generating random numbers For this lab you should write a program that contains a main function and one additional function (to generate random numbers and determine if the random number is equal to, below or above a given number). Your main function should prompt the user to enter a whole number between 0 and 100 not including 0 and 100 hundred. (You may assume the user enters a valid number or check it within main as practice). Your main should then call the function. After the function has completed, your main function should output how many of the generated numbers were equal to the entered value, how many of the generated numbers were less than the entered value, and how many of the generated numbers were greater than the entered value. Your function should use a loop to generate 100 random numbers between 0 and 100 including 0 and 100, then count how many of the generated numbers were equal to the entered value, how many were less than the entered value, and how many were greater than the entered value. Your function should send how many were equal to, less than, and greater than the entered value back to the function call in main.

Do not use global variables and place your function after main. Remember to write comments immediately before your function that specifies the purpose of the function, input to the function (both what is passed to the function and any input generated within the function), output from the function (both what is sent back to the function call and what is printed to the screen) and processing needed. The comments for your function should be in addition to the overall comments for the program.

Solution

#include<stdio.h>

#include<stdlib.h>

int main()

{

printf(\"\ enter a number between 0 and 100 : \");

int n;

scanf(\"%d\",&n);

rando(n);//function call

return 0;

}

void rando(int n)

{

int a[10];

int gt=0,lt=0,eq=0;

for(int i=0;i<10;i++)

{

a[i]=rand()%100;/* generate random number between 0 and100*/

if(a[i]>n)gt++;

if(a[i]<n)lt++;

if(a[i]==n)eq++;

}

printf(\"\ no of integers out of 10: \ less than %d are %d\ greater than %d are %d\ equal to %d are %d\",n,lt,n,gt,n,eq);

}

using c++ Practicing reference parameters and generating random numbers For this lab you should write a program that contains a main function and one additional
using c++ Practicing reference parameters and generating random numbers For this lab you should write a program that contains a main function and one additional

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site