-
Notifications
You must be signed in to change notification settings - Fork 0
/
1b_1.c
49 lines (35 loc) · 800 Bytes
/
1b_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 5
/* swap function x and y */
void swap(int *x, int *y){
int tmp ;
tmp = *x;
*x = *y;
*y = tmp;
}
int main(){
int a[SIZE], i, j, m;
srand(time(0));
m = SIZE;
printf("Initial random generated array (0 - 100): \n");
for (i=0; i < SIZE ; i++){
a[i] = rand() % 100;
printf("%d ", a[i] );
}
printf("\n");
printf("Enter number that is not greater than %d and not less than 1 \n",m );
scanf("%d",&m);
for (j=1; j < SIZE + 1 - m; j++){
for (i=SIZE - 1; i > 0 ; i--){
swap(&a[i],&a[i-1]);
}
}
printf("Transformed array: \n" );
for (i=0; i < SIZE ; i++){
printf("%d ", a[i] );
}
printf("\n");
return 0;
}