第一题、
#import <Foundation/Foundation.h>
float aver(float arr[],int n)
{
float *i;
float *end=arr+n;
float sum=0,averf;
for (i=arr; i<end; i++)
sum+=*i;
averf=sum/n;
return averf;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
float array(float arr[],int n);
float arr[]={1,2,3,4,5,6,7,8,9,10};
NSLog(@"%.2f", aver(arr,10));
}
return 0;
}
第三题、
#import <Foundation/Foundation.h>
int SieveofErastosthenes(int n )
{
int p[]={0};
int i,j;
for (i=2; i<n; i++)
p[i]=1;
for (i=2; i*i<n; i++)
{
if (p[i])
for (j=i; i*j<n; j++)
p[i*j]=0;
}
for (i=2; i<=n; i++)
{
if (p[i])
NSLog(@"%i",i);
}
return i;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
int SieveofErastosthenes(int n );
NSLog(@"%i",SieveofErastosthenes(150));
}
return 0;
}
本题还有问题,没有找出来,请大神指点