Sunteți pe pagina 1din 9

TALLER CICLOS FOR Y WHILE (C++)

MIGUEL ANGEL TOVAR

MICHAELL IBBAN GARCIA PERDOMO

UNIVERSIDAD ANTONIO NARIÑO, SEDE BUGANVILES

PROGRAMA DE INGENIERÍA ELECTRONICA

NEIVA, HUILA

ABRIL 2018
Realizar los ejercicios con el ciclo for en estilo cout y printf.

1) Calcular el promedio de un alumno que tiene 7 calificaciones en la materia


de Diseño Estructurado de Algoritmos
COUT

#include <iostream>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main(int argc, char *argv[]) {


int i;
float cal, sum=0, prom;
system ("color f4");

cout<<"NOTA PROMEDIO DISEÑO ESTRUCTURADO DE


ALGORITMOS\n\n"<<endl;

for (i=1;i<=7;i++){
cout<<"ingrese la calificacion : "<<i<<endl;
cin>>cal;
sum=sum+cal;
}
prom=sum/7;
cout<<"\nEL PROMEDIO DE SU CALIFICACION ES:"<<prom<<endl;

return 0;
}
2) Leer 10 números y obtener su cubo y su cuarta.
COUT FOR

#include <iostream>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main(int argc, char *argv[]) {


int i;
float num,cub=0, cu=0;
system ("color f4");

cout<<"OBTENER SU CUBO Y SU CUARTA\n\n"<<endl;

for (i=1;i<=10;i++){

cout<<"ingrese numero : "<<i<<endl;


cin>>num;
cub=num*num*num;
cu=cub*num;

cout<<"\nsu cubo es: "<<cub<<endl;


cout<<"\nsu cuarta es:"<<cu<<endl;
}
return 0;
}
3) Leer 10 números e imprimir solamente los números positivos

COUT

#include <iostream>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main(int argc, char *argv[]) {


int i;
float num;
system ("color f4");

cout<<"IMPRIMIR SOLAMENTE LOS NUMEROS


POSITIVOS\n\n"<<endl;

for (i=0;i<=10;i++){

cout<<"ingrese numero : "<<endl;


cin>>num;
if (num>0)
cout<<"\nel numero positivo es: "<<num<<endl;

}
return 0;
}
4) Leer 20 números e imprimir cuantos son positivos, cuantos negativos y
cuantos neutros.
COUT
#include <iostream>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main(int argc, char *argv[]) {


int i;
float num,n=0, p=0, neg=0;
system ("color f4");

cout<<"CUANTOS SON POSITIVOS,NEGATIVOS Y


NEUTROS\n\n"<<endl;

for (i=1;i<=20;i++){

cout<<"ingrese numero : "<<i<<endl;


cin>>num;
if (num==0){
n++;}
else if (num>0){
p++;}
else{
neg++;}
}
cout<<"\nSon positivos: "<<p<<endl;
cout<<"\nSon negativos:"<<neg<<endl;
cout<<"\nSon neutros: "<<n<<endl;

return 0;
}
5) Leer 15 números negativos y convertirlos a positivos e imprimir dichos
números.

PRINTF
#include <iostream>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main(int argc, char *argv[]) {


int i;
float num,pos=0;
system ("color f4");

printf("NEGATIVOS CONVERTIRLOS A POSITIVOS\n\n");

for (i=1;i<=20;i++){
printf("ingrese numero %d: ",i);
scanf("%f",&num);
pos = num * -1;

printf("\nel numero ingresado es: %.0f", num);


printf("\nel numero positivo es: %.0f", pos);

return 0;
}
6) Suponga que se tiene un conjunto de calificaciones de un grupo de 40
alumnos. Realizar algoritmo para calcular la calificación media y la
calificación más baja de todo el grupo.
PRINTF
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[]) {
system ("color 12");
float i, nota, baja, prom, media;
media=0;
baja=5;
for (i=1;i<=40;i++){
printf("\nDigite la calificacion del alumno: %0.0f \n",i);
scanf("%f",&nota);
if (nota>=0){
if (nota<baja){
baja=nota;
}
}
media=media+nota;
}
prom=media/40;
printf("\n El promedio del grupo es: %0.1f",prom);
printf("\n La nota más baja fue: %0.1f", baja);
return 0;
}
7) Calcular e imprimir la tabla de multiplicar de un número cualquiera.
Imprimir el multiplicando, el multiplicador y el producto.
PRINTF

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

using namespace std;

int main(int argc, char *argv[]) {


system ("color 13");
int tabla, n, i;
cout<<"Qué tabla de multiplicar desea?"<<endl;
cin>>tabla;
cout<<"Hasta qué número quiere multiplicar la tabla"<<endl;
cin>>n;
for (i=1; i<=n; i++){
cout<<"\n"<<tabla<<"x"<<i<<"="<<tabla*i;
}

return 0;
}
8) Simular el comportamiento de un reloj digital, imprimiendo la hora, minutos
y segundos de un día desde las 0:00:00 horas hasta las 23:59:59 horas
PRINTF

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]) {


system ("color 20");
for (int h=00; h<=23; h++){
for (int m=00; m<=59; m++) {
for (int s=00; s<=59; s++){
printf("%d:%d:%d \n",h,m,s);
}
}
}
return 0;
}

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