再在a中找出與v最接近的數(shù)及其下標(biāo)?
/* Note:Your choice is C IDE */#include "stdio.h"#include "math.h"void main(){ int a[10],i,j,min; float b[10],sum=0,average; printf("請輸入10個整數(shù):")
; for (i=0; i<10; i++) { scanf("%d",&a[i]); sum+=a[i]; } average=sum/10; printf("\n平均數(shù)為:%f",average)
; for (i=0; i<10; i++) b[i]=fabs((a[i]-average)); min = 0; for (j=1; j<10; j++) { if (b[j] < b[min]) { min = j; } } printf("\n與平均數(shù)最相近的是數(shù)是:%d",a[min])
; printf("\n它是第%d個數(shù)",min); }