猿问

求教程序代码



城东有家可乐店
浏览 1405回答 3
3回答

小江xue

# include<stdio.h>void pra(int num)// 输出众数个数 众数 次数{    double buff[30][2];//保存输入元素 及出现次数    double buff2[30];    double t;    int n = 0, i, j;    int max_n = 0;//最高出现次数    if( 0 == num)        return;    else    {        //输入数据        for(n = 0; n < num ; n++)        {            scanf("%lf", &buff[n][0]);            buff[n][1] = 0.0;        }         //排序(前面)        for(i = 0;i< num-1;i++)        {           for(j = 0;j<num-1-i;j++)           {               if(buff[j][0] > buff[j+1][0])               {                   t = buff[j][0];                   buff[j][0] = buff[j+1][0];                   buff[j+1][0] = t;               }           }        }        //计算出现次数        for(i = 0;i < num; i++)        {            for(j = 0; j < num;j++)            {                if(buff[i][0] == buff[j][0])                    buff[i][1]+= 1;            }            if(buff[i][1] > max_n)                max_n = (int)buff[i][1];        }       //计算        for(i = 0, j = 0;i<num;i++)        {            if(max_n==buff[i][1])            {                if(0 == j|| buff2[j - 1]!= buff[i][0])                {                    buff2[j] = buff[i][0];                    j++;                }            }        }        //输出        printf("%d ", j );        for(i = 0;i < j;i++)            printf("%.2lf ", buff2[i]);        printf(" %d\n", max_n);    }}int main(void){    int num;    do    {        scanf("%d", &num);        pra(num);    }while(0 != num);    return 0;}//chu xue zhe ben 人    嘿嘿
随时随地看视频慕课网APP
我要回答