Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140520 Exam 11 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/05/20 am.11:40 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void main()
- {
- srand(time(NULL));
- int random_array[100] = {EOF};
- for(int i = 0; i < 100; i++)
- {
- random_array[i] = rand() % (15 - 1 + 1) + 1;
- }
- int counter = 0;
- for(int i = 100 - 1; i > 0; i--)
- {
- for(int j = 0; j <= i - 1; j++)
- {
- if (random_array[j] > random_array[j + 1])
- {
- int temp = 0;
- temp = random_array[j];
- random_array[j] = random_array[j + 1];
- random_array[j + 1] = temp;
- counter++;
- }
- }
- }
- int sum = 0;
- for(int i = 0; i < 100; i++)
- {
- sum += random_array[i];
- }
- int number_counter[15][2] = {0};
- for(int i = 0; i < 100; i++)
- {
- if(i < 15)
- {
- number_counter[i][0] = i + 1;
- }
- number_counter[random_array[i] - 1][1]++;
- }
- int max[2] = {0};
- for(int i = 0; i < 15; i++)
- {
- if(number_counter[i][1] > max[1])
- {
- max[0] = number_counter[i][0];
- max[1] = number_counter[i][1];
- }
- }
- printf("Random integer = {");
- for(int i = 0; i < 100; i++)
- {
- if(i == 99)
- {
- printf("%d}\n", random_array[i]);
- break;
- }
- printf("%d, ", random_array[i]);
- }
- printf("\n");
- printf("Number of cahng times: %d.\n"\
- "Mean: %2.2f.\n"\
- "Mode: %2.2f.\n"\
- "Median: %2d.\n\n"\
- ,counter, (float)sum / 100, (float)(random_array[50] + random_array[51]) / 2, max[0]);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment