0% found this document useful (0 votes)
35 views8 pages

Miscelanea For: Prof. Oscar Tinoco G

The document contains code snippets for several C++ programs. The first two programs use nested for loops to output the numbers 1 through 5 in different formats. The third program calculates the sum of a series using a for loop. The fourth program uses nested for loops to determine if numbers from 1 to 1000 are prime. The fifth program outputs all prime numbers within a given range using nested for loops.

Uploaded by

maarco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views8 pages

Miscelanea For: Prof. Oscar Tinoco G

The document contains code snippets for several C++ programs. The first two programs use nested for loops to output the numbers 1 through 5 in different formats. The third program calculates the sum of a series using a for loop. The fourth program uses nested for loops to determine if numbers from 1 to 1000 are prime. The fifth program outputs all prime numbers within a given range using nested for loops.

Uploaded by

maarco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

MISCELANEA FOR

Prof. Oscar Tinoco G

Elaborar un programa que muestre los nmeros


del 1 al 5 de la siguiente manera:

#include<iostream>
using namespace std;
main()
{
int i, j;
for(i=1; i<=5;i++)
{
for(j=1; j<=5;j++)
{
cout<<j<<"\t";
}
cout<<endl;
}
}

Elaborar un programa que muestre los nmeros


del 1 al 5 de la siguiente manera:

#include<iostream>
using namespace std;
main()
{
int i, j;
for(i=1; i<=5;i++)
{
for(j=i; j<=5;j++)
{
cout<<j<<"\t";
}
cout<<endl;
}
}

Algoritmo

#include<iostream.h>
using namespace std;
main()
{
int i,M;
float sum=0,t;
cout<<"Ingresar el valor de
M:\n";
cin>>M;
for(i=1; i<=M;i++)
{
t=1./(2*i-1);
cout<<t<<" ";
sum=t+sum;
}
cout<<"\n Suma serie:

#include <iostream>
using namespace std;
main()
{
int i,j, num, primo;
for ( j=1; j <= 1000; j++ )
{
for ( i = 2; i < j; i++ )
{
if ( j % i == 0)
{
primo = 0;
break;
}
else
primo = 1;
}
if ( primo == 1)
cout<<j<<" es primo"<<endl;
}
}

// primos en un intervalo
#include <iostream>
using namespace std;
main()
{
int a, b, c, i, n, primo;
cout<< "Introduzca un intervalo de nros\n";
cin>> a >> b;
cout<< endl;
if ( b < a )
{
c = a;
a = b;
b = c;
}
for ( n = a; n <= b; n++ )
{
for ( i = 2; i < n; i++ )
{
if ( n % i == 0)
{
primo = 0;
break;
}
else

}
if ( primo == 1)
cout<<" "<< n;
}
}

You might also like