題目:
function1. allow user to enter an array of 6 float values
(輸入6個值)
function2. print 6 float value
function3. use return statement to return largest of the 6 the float value. print the largest in the main
找最大值, 在main function print出來
function4. sort array inn ascending(low to high) order.
老師說要這樣寫
#include<iostream>
using namespace std;
void load(float a[])
{
for (int i=0;i<=6;i++)
{
cout<<"Enter a value ";
cin>>a[i];
}
}
void print
{
code
}
void findbig
{
code
}
void sort
{
code
}
int main()
{
code
}
除了第一個function會寫外, 剩下三個不會寫 有人可以幫忙一下嗎m(_ _)m 感謝
answer:
#include <iostream>
#include <string>
void load(float *a,float inx);
void sort(float *s,float inx);
float findbing(float *f,float inx);
void print(float *p,float inx);
using namespace std;
void load(float *a,float inx)
{
for (int i=0;i<=inx;i++)
{
cout<<"Enter a value["<<i<<"]=";
cin>>a[i];
}
}
void sort(float *s,float inx)
{
int i,k;
float temp=0;
for(i=0;i<=inx;i++)
{
for(k=i+1;k<=inx;k++)
{
if(s[i]>s[k])
{
temp=s[i];
s[i]=s[k];
s[k]=temp;
}
}
}
}
float findbing(float *f,float inx)
{
return f[5];
}
void print(float *p,float inx)
{
for(int i=0;i<=inx;i++)
cout<<"["<<i<<"]="<<p[i]<<endl;
}
int main(int args,char * argv[])
{
float a[5]={0},g;
load(a,5);
sort(a,5);
g=findbing(a,5);
cout<<"最大值為="<<g<<endl;
print(a,5);
return 0;
}
留言列表