You are on page 1of 3

TABLA DE MULTIPLICAR: #include "stdafx.h" #include "iostream.

h" int main(int argc, char* argv[]) { int numero,n; cout<<"Ingrese numero=";cin>>numero; for (n=1;n<=18;n++) { cout<< numero << "*" << n << "=" << (numero*n) << endl; } } NUMERO PRIMO #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int numero, n, contan; cout<<"Ingrese numero=";cin>>numero; contan=0; for (n=1;n<=numero;n++) { if(numero%n==0) { cout<<n<<endl; contan++; } } if(contan ==2) cout<<"Numero Primo"<<endl; else cout<<"Numero no primo"<<endl; } SUMA DE N NUMEROS #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int n, i, suma=0, suma1=0, suma2=0; cout<<"Ingrese hasta que numero=";cin>>n; for(i=1;i<=n;i++) { suma=suma+i;

} cout<<"Suma de los n primeros numeros="<< suma <<endl; cout<<"Ingrese hasta que numero=";cin>>n; for(i=1;i<=n;i++) { suma1=suma1+(i*i); } cout<<"Suma de cuadrados de los n primeros numeros="<< suma1 <<endl; cout<<"Ingrese hasta que numero=";cin>>n; for(i=1;i<=n;i++) { suma2=suma2+(i*i*i); } cout<<"Suma de cubos de los n primeros numeros="<< suma2 <<endl; } FATORIAL DE UN NUMERO #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int numero, i, producto=1; cout<<"Ingrese numero=";cin>>numero; for(i=1;i<=numero;i++) { producto=producto*i; } cout<<"Resultado de factorial="<<producto<<endl; } PROMEDIO MAX NOTA MIN NOTA #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int n, nota, suma=0, notamin=0, notamax=20; for(n=1;n<=15;n++) { cout<<"Ingrese nota=";cin>>nota; suma=suma+nota; if(notamax>nota) { notamax=nota;

} if(notamin<nota) { notamin=nota; } } cout<<"Promedio de notas="<<suma<<endl; cout<<"Nota maxima="<<notamin<<endl; cout<<"Nota minima="<<notamax<<endl; } SUMA DE N PRIMEROS NUMEROS IMPARES POSITIVOS #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int n, suma=0, impar=1, cont=1; cout<<"Ingrese numero=";cin>>n; while (cont<=n) { suma=suma+impar; impar=impar+2; cont++; } cout<<"Suma total="<<suma<<endl; } SUMA DE FRACCIONES CON DENOMINADOR PAR #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int n, a=1, par=0; float suma=0; cout<<"Ingrese numero=";cin>>n; while(a<=n) { par=par+2; suma=suma+ (float)1/par; a++; } cout<<"Resultado="<<suma<<endl; }

You might also like