-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorr_circ.c
More file actions
71 lines (54 loc) · 1.16 KB
/
scorr_circ.c
File metadata and controls
71 lines (54 loc) · 1.16 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#define DIM_MAX 256
int leggi_vettore(int dim_max, int v[DIM_MAX]);
void scorrimento_circolare(int dim, int v[DIM_MAX]);
void stampa_vettore(int dim, int v[DIM_MAX]);
int main()
{
int dim;
int v[DIM_MAX];
dim = leggi_vettore(DIM_MAX, v);
scorrimento_circolare(dim, v);
stampa_vettore(dim, v);
return EXIT_SUCCESS;
}
int leggi_vettore(int dim_max, int v[])
{
int i;
int dim;
printf("Inserisci il numero di valori da scrivere nel vettore: ");
scanf("%d", &dim);
while (dim > DIM_MAX)
{
printf("Numero troppo elevato: reinseriscilo:");
scanf("%d", &dim);
}
for(i = 0; i < dim; i++)
{
printf("v[%d] = ", i);
scanf("%d", &v[i]);
}
return dim;
}
void scorrimento_circolare(int dim, int v[])
{
printf("Applico lo scorrimento...\n");
int i;
int temp = v[dim -1];
for(i = dim - 2; i >= 0; i--)
{
v[i+1] = v[i];
}
v[0] = temp;
return;
}
void stampa_vettore(int dim, int v[])
{
int i;
for(i=0; i<dim; i++)
{
printf("v[%d] = %d\n", i, v[i]);
}
return;
}