Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140513 Exam 10 **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/04/13 pm.11:40 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void main()
- {
- printf("Enter a number: ");
- int input = 0, random_array[9999];
- scanf("%d", &input);
- srand(time(NULL));
- for(int i = 1; i <= input; i++)
- {
- random_array[i] = rand() % (10 - 1 + 1) + 1;
- }
- printf("Random array = {");
- for(int i = 1; i <= input; i++)
- {
- if(i != input)
- {
- printf("%d, ", random_array[i]);
- }
- else if(i == input)
- {
- printf("%d}\n", random_array[i]);
- }
- }
- printf("Answer = {");
- switch(input % 2)
- {
- case 0:
- for(int i = 1; i <= input / 2; i ++)
- {
- if(i != input / 2)
- {
- printf("%d, ", random_array[i] + random_array[input + 1 - i]);
- }
- else if(i == input / 2)
- {
- printf("%d}\n", random_array[i] + random_array[input + 1 - i]);
- }
- }
- break;
- case 1:
- for(int i = 1; i <= input / 2 + 1; i ++)
- {
- if(i != input / 2 + 1)
- {
- printf("%d, ", random_array[i] + random_array[input + 1 - i]);
- }
- else if(i == input / 2 + 1)
- {
- printf("%d}\n", random_array[i]);
- }
- }
- break;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment