Aprende a leer, Escribir e intercambiar una posicion de un arreglo ( En lenguaje C)

in #tecnology6 years ago

Sabes como leer y escribir arreglos en lenguaje c ?

Aqui aprenderas como hacerlo de forma rápida y sencilla, a través de una serie de subprogramas que te ayudaran de comprender el como programar en lenguaje c. Luego veras como en el main se hacen los respectivos llamados a cada subprograma.
Puedes ajustar el tamaño de tu arreglo como lo desees.

#include <stdio.h>
#include <stdlib.h>

void swap(int *a,int b){
int t=
a; a=b; *b=t;
}

void leeArreglo(int a[], int n){
int i=0;
while(i<n)

{
    printf("\na[%d] = ",i);
    scanf("%d", &a[i]);
    i++;
}

}

void escribeArreglo(int a[], int n){
int i=0;
printf("\n[ ");
while(i<n-1) printf("%d,",a[i++]);
if(n>0) printf("%d]",a[i]); else printf("]");
}

int main()
{
int n=8; int a[n];
leeArreglo(a,5);
escribeArreglo(a,5);
swap(&a[0],&a[4]);
escribeArreglo(a,5);
return 0;
}

Espero y te sirva.

Sort:  

De eso no se mucho pero bien educativo. Tienes mi Vto.

Congratulations @justimdanigss! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60379.35
ETH 2434.58
USDT 1.00
SBD 2.47