+ 1
Write a function that takes 3 arguments : the name of 'FLOAT' array,the array size,and a 'FLOAT' value.[continued]
[continued] Have the function set each element of the array to 'FLOAT' value ?
2 ответов
+ 3
void function (float arr[], int n, float x){
int i=0;
for (i=0; i<n; i++){
arr[i] = x;
}
}
+ 1
#include <iostream>
using namespace std;
void func(float *arrPtr, int arrSize, float arrVal)
{
if(arrPtr != NULL)
{
for(int i = 0; i < arrSize; i++)
{
arrPtr[i] = arrVal;
}
}
}
int main()
{
//Prg 1 Start
float arrFloat[10];
func(arrFloat,10,50);
for(int i = 0; i < 10; i++)
{
cout << "Arr[" << i << "] => " << arrFloat[i] << endl;
}
}