Programacion estructurada
-
Upload
christian-cruz -
Category
Documents
-
view
223 -
download
0
description
Transcript of Programacion estructurada
![Page 1: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/1.jpg)
UNIVERSIDAD TÉCNICA DE AMBATO
FACULTAD CIENCIAS HUMANAS Y DE
LA EDUCACIÓN
CARRERA DE: DOCENCIA EN INFORMÁTICA Y COMPUTACIÓN
NOMBRE: CRISTIAN CRUZ
“PROGRAMACION”
![Page 2: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/2.jpg)
PRIMOS EN UNA MATRIZ
Realice un programa con funciones que me permita ingresar una matriz de
cualquier valor que se genere todos los números primos.
ANALISIS
Primero colocamos las librerías después las variables globales.
Comenzamos con la función borde donde realizamos el proceso, cerramos
la función seguido creamos otra función para los primos donde realizamos
el proceso de realizar 2 for para que después con un if preguntemos si la
división de un número es igual a la unidad y para otros más donde tiene
que dar como resultado 0 si la división es más que dos ceros no es numero
primo si no si lo es.
Luego otra función donde tenemos que imprimir en la matriz y ya está las
funciones completas, luego el programa principal donde llamamos el
programa.
![Page 3: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/3.jpg)
Codificado
include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
int matriz1[10][10],i,j,f1=0,t=0,op=0,f=0,primo=1,x=1,conpri=0,sw=0;
void encerar(int n)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
matriz1[i][j] = 0;
}
}
}
void primos(int n)
{
primo=1;
sw=0;
for(i=1;i<=n;i++)
![Page 4: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/4.jpg)
{
for(j=1;j<=n;j++)
{
do
{
conpri=0;
sw=0;
for(x=1;x<=primo;x++)
{
if((primo%x)==0)
{
conpri++;
}
}
if(conpri<=2)
{
matriz1[i][j] = primo;
primo++;
sw=1;
}
else
{
sw=0;
primo++;
}
}
![Page 5: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/5.jpg)
while (sw==0);
}
}
}
void imprimir(int a)
{
t=5;
f1=7;
for(i=1;i<=a;i++)
{
for(j=1;j<=a;j++)
{
gotoxy(t,f1);printf("%d",matriz1[i][j]);
t=t+6;
}
t=5;
f1=f1+2;
}
}
void borde()
{
![Page 6: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/6.jpg)
clrscr();
for (i=1;i<=80;i++)
{
gotoxy(i,1); printf("*");
gotoxy(i,24); printf("*");
}
for (i=1;i<=24;i++)
{
gotoxy(1,i); printf("*");
gotoxy(80,i); printf("*");
}
}
void main()
{
do
{
clrscr();
borde();
borde();
![Page 7: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/7.jpg)
gotoxy(12,2); printf(" M A T R I Z C O N P R I M O S ");
gotoxy(12,3); printf("__________________________________");
do
{
gotoxy(55,5); printf(" ");
gotoxy(10,5); printf("Ingrese el limite => ");scanf("%d",&f);
}
while (f<1 || f >9);
encerar(f);
primos(f);
imprimir(f);
gotoxy(5,23); printf("Presione 1 para continuar 0 para finalizar =>");scanf("%d",&op);
}
while (op==1);
}
![Page 8: Programacion estructurada](https://reader036.fdocumento.com/reader036/viewer/2022081808/5695d3b01a28ab9b029ed32e/html5/thumbnails/8.jpg)
Corrido