Using Microsoft Visual Studios write a program in C with two functions. The main
ID: 3687212 • Letter: U
Question
Using Microsoft Visual Studios write a program in C with two functions. The main function will just define and initialize the variables and call the user functions. All the work will be done by the user functions. The size of the array is 25. Initialize the float array to -99.88. Call function #1. Call function #2.
Function #1: this function will be passed a float array and its size and return nothing. The function will fill the array with random floats between 1 and 10 (inclusive). Use the formula below:
x[i] = 10 * (float) rand() / (float) (RAND_MAX);
Function #2: Print the array to the screen. Print one number per line.
Explanation / Answer
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
float function1(float[],float);
//main function
void main()
{
float arr[25]={-99.88};
function1(arr,25);
getch();
}
//function definition to update and print the array
float function1(float a[],float n)
{
int i;
for(i=0;i<n;i++)
{
a[i] = 10 * (float) rand() / (float) (RAND_MAX);
}
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.