Sunteți pe pagina 1din 7

GUA N 4

SOLUCIN DE EJERCICIOS

PREGUNTA N 1
Desarrolle un programa que permita ingresar 4 notas en un arreglo y calcule el
promedio de notas.

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main()
{
float notas[4];
int i;
float prom, suma = 0;
for(i=0; i<4; i++)
{
printf("Ingrese la nota %d : ", i+1);
scanf("%f", &notas[i]);
}
for(i=0; i<4; i++)
{
suma = suma + notas[i];
}
prom = suma / 4;
printf("El promedio de notas es %.2f\n\n", prom);
system("pause");
}

PREGUNTA N 2
Desarrolle un programa que rellene un arreglo con los 20 primeros nmeros enteros
y los muestre en pantalla en orden ascendente.

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
main()
{
int x,tabla[20];
for (x=0; x<20; x++)
{
tabla[x]=x+1;
}
for (x=0;x<20;x++)
{
printf("%d\n",tabla[x]);
}
system("PAUSE");
}

PREGUNTA N 3
Desarrolle un programa que rellene un arreglo con los nmeros pares comprendidos
entre 1 y 20 y los muestre en pantalla en orden ascendente

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
main()
{
int x, cont, z, i, tabla[20];
i=0;
for (x=1; x<=20; x++)
{
cont=0;
if (x%2==0)
{
tabla[i]=x;
i++;
}
}
for (x=0; x<i; x++)
{
printf("%d\n",tabla[x]);
}
system("PAUSE");
return 0;
}

PREGUNTA N 4
Desarrolle un programa que lea 5 nmeros por teclado, los copie a otro arreglo
multiplicado por 2 y muestre el segundo arreglo.

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
main()
{
int aux, numeros1[5], numeros2[5];
int i, j;
for (i=0; i<5; i++)
{
printf("Escriba numero %d : ", i+1);
scanf("%d", &numeros1[i]);
}
for(i=0; i<5; i++)
{
numeros2[i]=numeros1[i]*2;
}
for (i=0; i<5; i++)
{
printf("%d\n", numeros2[i]);
}
}

system("PAUSE");

PREGUNTA N 5
Desarrolle un programa que lea 5 nmeros por teclado, los almacene en un arreglo y
los ordene de forma ascendente:

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
int main()
{
int aux, numeros[5];
int i, j, n=5;
for (i=0; i<n; i++)
{
printf("Escriba numero %d : ", i+1);
scanf("%d", &numeros[i]);
}
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(numeros[i] < numeros[j])
{
aux=numeros[i];
numeros[i] = numeros[j];
numeros[j] = aux;
}
}
}
for (i=n-1; i>=0; i--){
printf("%d\n", numeros[i]);
}
system("PAUSE");
return 0;
}

PREGUNTA N 6
Desarrolle un programa que rellene un arreglo con los 20 primeros nmeros pares y
muestre su suma

SOLUCIN
#include <stdio.h>
#include <stdlib.h>
main()
{
int x, cont, sum, i, tabla[20];
i=0;
sum=0;
for (x=1; x<=20; x++)
{
cont=0;
if (x%2==0)
{
tabla[i]=x;
i++;
}
}
for (x=0; x<i; x++)
{
sum = sum + tabla[x];
}
printf("%d\n",sum);
system("PAUSE");
}

S-ar putea să vă placă și