gpt4 book ai didi

c - 将值分类到适当的组中 : Counter Arrays

转载 作者:行者123 更新时间:2023-11-30 17:09:52 24 4
gpt4 key购买 nike

  #include <stdio.h>
#include <stdlib.h>
#include <math.h>




int main(){

int i;
int sales[30];
int arraySize = 0;
int temp[10] = { 0 };

for (i = 0; i < 30; i++)
{
sales[i] = (rand() % 15000) + 1; between 0 and 15000
}


printf("Gross Sales of all 30 Salespeople\n");


for (i = 0; i < 30; i++)
{
printf("%d\n", sales[i]); //Displays Orginal List and Lists all values that were randomly selected
}


printf("\nWage based on Gross Sales \n"); //Displays calculated wages with math equation


for (i = 0; i < 30; i++)
{
printf("%f\n", 100 + (float)sales[i] * 0.09); //Mathematical equation
}


for (i = 0; i < 30; i++)

while (arraySize >= 0)
{
{
if (sales[arraySize] >= 1000)
temp[9]++;
else if (sales[arraySize] >= 900)
temp[8]++;
else if (sales[arraySize] >= 800)
temp[7]++;
else if (sales[arraySize] >= 700)
temp[6]++;
else if (sales[arraySize] >= 600)
temp[5]++;
else if (sales[arraySize] >= 500)
temp[4]++;
else if (sales[arraySize] >= 400)
temp[3]++;
else if (sales[arraySize] >= 300)
temp[2]++;
else if (sales[arraySize] >= 200)
temp[1]++;
else
temp[0]++;


arraySize--;

printf("\n");
printf("$100-$199 : %d\n", temp[0]);
printf("$200-$299 : %d\n", temp[1]);
printf("$300-$399 : %d\n", temp[2]);
printf("$400-$499 : %d\n", temp[3]);
printf("$500-$599 : %d\n", temp[4]);
printf("$600-$699 : %d\n", temp[5]);
printf("$700-$799 : %d\n", temp[6]);
printf("$800-$899 : %d\n", temp[7]);
printf("$900-$999 : %d\n", temp[8]);
printf(">>>$1000 : %d\n", temp[9]);

break;
}
}
return 0;

}

我正在编写一个程序,它会在数组中随机选择 30 个数字,然后对这些数字使用数学方程,然后根据每个组对数字进行排序。除了将它们分类到每个选定的组中之外,我已经能够让一切正常工作。我做错了什么,我该如何解决这个问题。顺便说一句,我对编程非常陌生,因此非常感谢任何帮助

最佳答案

请尝试这个:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main( )
{
int i;
int sales[30];
int arraySize = 0;
int temp[10] = { 0 };

for ( i = 0; i < 30; i++ )
{
sales[i] = ( rand( ) % 15000 ) + 1; // between 0 and 15000
}

printf( "Gross Sales of all 30 Salespeople\n" );

for ( i = 0; i < 30; i++ )
{
printf( "%d\n", sales[i] ); //Displays Orginal List and Lists all values that were randomly selected
}
printf( "\nWage based on Gross Sales \n" ); //Displays calculated wages with math equation


// this does not do anything
// for ( i = 0; i < 30; i++ )
// {
// printf( "%f\n", 100 + ( float ) sales[i] * 0.09 ); //Mathematical equation
// }

//让我们做点什么 对于(i=0;i<30;i++) { printf("在这里对 %d\n 应用一些计算", sales[i]); 销售额[i]=100 + ( float ) 销售额[i] * 0.09;//数学方程 printf( "并且它变成 %f\n", ( float )sales[i]); }

  for ( i = 0; i < 30; i++ )
{
printf("\n sorting sales %d == %d " , i , sales[i] );

if ( sales[i] >= 1000 )
temp[9]++;
else if ( sales[i] >= 900 && sales[i]<=999)
temp[8]++;
else if ( sales[i] >= 800 && sales[i]<=899)
temp[7]++;
else if ( sales[i] >= 700 && sales[i]<=799)
temp[6]++;
else if ( sales[i] >= 600 && sales[i]<=699)
temp[5]++;
else if ( sales[i] >= 500 && sales[i]<=599)
temp[4]++;
else if ( sales[i] >= 400 && sales[i]<=499)
temp[3]++;
else if ( sales[i] >= 300 && sales[i]<=399)
temp[2]++;
else if ( sales[i] >= 200 && sales[i]<=299)
temp[1]++;
else
temp[0]++;

}

printf( "\n" );
printf( "$100-$199 : %d\n", temp[0] );
printf( "$200-$299 : %d\n", temp[1] );
printf( "$300-$399 : %d\n", temp[2] );
printf( "$400-$499 : %d\n", temp[3] );
printf( "$500-$599 : %d\n", temp[4] );
printf( "$600-$699 : %d\n", temp[5] );
printf( "$700-$799 : %d\n", temp[6] );
printf( "$800-$899 : %d\n", temp[7] );
printf( "$900-$999 : %d\n", temp[8] );
printf( ">>>$1000 : %d\n", temp[9] );
return 0;
}

关于c - 将值分类到适当的组中 : Counter Arrays,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33114729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com