Decreasing array

  • File name: Decreasing array
  • Size: 529 b
yes /

Download

The following code returns 1 and prints out "The vector is ordered decreasingly" if the values of the array keyed in are decreasing order, for example, 35, 34, 33, 20, 15, 12, 10, 9, 5, 4.

In case you are not decreasing order the function returns 0 and displays "The vector is not ordained."

The values are stored in an array / vector of 10 fields with which we will work to save the entered numbers and to verify that it is decreasing.


 


#include <stdio.h>
#define DIM 10

int ordenado(double v[],int n){

    int aux=1;int i;

    for(i=0;i<n&&aux==1;i++){
        if(v[i]>v[i+1])aux=1;
        else aux=0;
    }
    return aux;
}


int main(){
    double x[DIM];int d=10;int aux;int i;

    printf("Escribe las componentes del vector de 10 elementos\n");
    for(i=0;i<d;i++){
        scanf("%lf",&x[i]);
    }
    aux=ordenado(x,d);

    if(aux==1)printf("El vector esta ordenado decrecientemente");
    else printf("El vector no esta ordenado");

    return 0;
}

 

More exercices in https://www.youtube.com/channel/UCK05KbyByXPCMRJEqyL4VXw/videos

No ratings yet - be the first to rate this.

Add a comment

You're using an AdBlock like software. Disable it to allow submit.