Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #define N 10
- int ordinamentocrescente(int a[N],int b[N]);int ordinamentomodulo100(int a[N],int b[N]);
- int main(){int a[10],b[10],i;
- for (i=0;i<N;i++){
- b[i]=i;
- }
- //INSERIMENTO
- for (i=0;i<N;i++) { do{
- printf ("Inserire i numeri.Posizione :%d\n",i+1);
- scanf ("%d",&a[i]);
- if (a[i] < 0 || a[i]> 1000) printf ("Errore nei dati. 0<=N<1000\n");
- }while (a[i] < 0 || a[i]> 1000) ;
- }
- printf("\n--------------------------------------------\n");
- ordinamentocrescente(a,b);
- //STAMPA
- for (i=0;i<N;i++) {
- printf ("%d\n",a[b[i]]);
- }
- ordinamentomodulo100(a,b);
- //STAMPA
- printf("\n--------------------------------------------\n");
- for (i=0;i<N;i++) {
- printf ("%d\n",a[b[i]]);
- }
- }
- int ordinamentocrescente(int a[N],int b[N]) {
- int save,i,j;
- for (int i=0; i<N-1; i++) {
- for (int j=i+1; j<N; j++) {
- if (a[b[i]]>a[b[j]]) {
- save=b[i];
- b[i]=b[j];
- b[j]=save;
- }
- }
- }
- }
- int ordinamentomodulo100(int a[N],int b[N]) {
- int save,i,j;float c,d;
- for (i=0;i<N;i++){
- b[i]=i;
- }
- for (int i=0; i<N-1; i++) {
- for (int j=i+1; j<N; j++) {
- if ((c=a[b[i]]%100)>(d=a[b[j]]%100)) {
- save=b[i];
- b[i]=b[j];
- b[j]=save;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement