Dada una matris y un vector, contar la cantidad de numeros primos de ambos
#include <stdio.h>
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] )
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
int primosMatris (int M[20][20], int f, int c)
{
int cant = 0;
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
int cc = 0;
for (int k = 1 ; k <= M [i] [j] ; k++)
{
if (M [i] [j] % k == 0)
cc++;
}
if (cc == 2)
cant++;
}
}
return (cant);
}
int primosVector (int V[20], int d)
{
int cant = 0;
for (int i = 1 ; i <= d ; i++)
{
int c = 0;
for (int j = 1 ; j <= V [i] ; j++)
{
if (V [i] % j == 0)
c++;
}
if (c == 2)
cant++;
}
return (cant);
}
int main()
{
int M [20] [20];
int V [20];
int f, c, d;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte columnas de la matris: ");
scanf("%d",&c);
printf ("Inserte dimension del vector: ");
scanf("%d",&d);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (M, f, c);
printf ("\nLLENANDO EL VECTOR: \n");
llenarVector (V, d);
printf ("\nLA MATRIS: ");
mostrarMatris (M, f, c);
printf ("\n\nEL VECTOR: \n");
mostrarVector (V, d);
int primos = primosMatris (M, f, c) + primosVector (V, d);
printf ("\n\nLA CANTIDAD DE NUMEROS PRIMOS QUE HAY EN LOS ARREGLOS ES: %d",primos);
getch();
}
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] )
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
int primosMatris (int M[20][20], int f, int c)
{
int cant = 0;
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
int cc = 0;
for (int k = 1 ; k <= M [i] [j] ; k++)
{
if (M [i] [j] % k == 0)
cc++;
}
if (cc == 2)
cant++;
}
}
return (cant);
}
int primosVector (int V[20], int d)
{
int cant = 0;
for (int i = 1 ; i <= d ; i++)
{
int c = 0;
for (int j = 1 ; j <= V [i] ; j++)
{
if (V [i] % j == 0)
c++;
}
if (c == 2)
cant++;
}
return (cant);
}
int main()
{
int M [20] [20];
int V [20];
int f, c, d;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte columnas de la matris: ");
scanf("%d",&c);
printf ("Inserte dimension del vector: ");
scanf("%d",&d);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (M, f, c);
printf ("\nLLENANDO EL VECTOR: \n");
llenarVector (V, d);
printf ("\nLA MATRIS: ");
mostrarMatris (M, f, c);
printf ("\n\nEL VECTOR: \n");
mostrarVector (V, d);
int primos = primosMatris (M, f, c) + primosVector (V, d);
printf ("\n\nLA CANTIDAD DE NUMEROS PRIMOS QUE HAY EN LOS ARREGLOS ES: %d",primos);
getch();
}
Dada la matrix de m*n y el vector de tamanio n, determinar que columna de la matris es igual al vector
#include <stdio.h>
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] );
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
void procedure (int M[20][20], int f, int c, int V[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int sw = 1;
for (int j = 1 ; j <= c ; j++)
{
for (int k = 1 ; k <= d ; k++)
{
if (M [j] [i] != V [k])
sw = 0;
}
}
if (sw == 1)
printf ("\n\nLa columna %d es igual al vector",i);
}
}
int main ()
{
int M [20] [20];
int V [20];
int f, d;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte dimension del vector: ");
scanf("%d",&d);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (M, f, d);
printf ("\nLLENANDO EL VECTOR: \n");
llenarVector (V, d);
printf ("\nLA MATRIS: ");
mostrarMatris (M, f, d);
printf ("\n\nEL VECTOR: \n");
mostrarVector (V, d);
procedure (M, f, d, V, d);
getch();
}
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] );
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
void procedure (int M[20][20], int f, int c, int V[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int sw = 1;
for (int j = 1 ; j <= c ; j++)
{
for (int k = 1 ; k <= d ; k++)
{
if (M [j] [i] != V [k])
sw = 0;
}
}
if (sw == 1)
printf ("\n\nLa columna %d es igual al vector",i);
}
}
int main ()
{
int M [20] [20];
int V [20];
int f, d;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte dimension del vector: ");
scanf("%d",&d);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (M, f, d);
printf ("\nLLENANDO EL VECTOR: \n");
llenarVector (V, d);
printf ("\nLA MATRIS: ");
mostrarMatris (M, f, d);
printf ("\n\nEL VECTOR: \n");
mostrarVector (V, d);
procedure (M, f, d, V, d);
getch();
}
Dada una matris Z almacenar en un vector A la suma por sus columnas
y en un vector B la suma por sus filas
Código:
#include <stdio.h>
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] );
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
void vectorA (int M[20][20], int f, int c, int A[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int suma = 0;
for (int j = 1 ; j <= c ; j++)
{
suma = suma + M [j] [i];
}
A [i] = suma;
}
}
void vectorB (int M[20][20], int f, int c, int B[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int suma = 0;
for (int j = 1 ; j <= c ; j++)
{
suma = suma + M [i] [j];
}
B [i] = suma;
}
}
int main ()
{
int Z [20] [20];
int A [20];
int B [20];
int f, c;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte columnas de la matris: ");
scanf("%d",&c);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (Z, f, c);
printf ("\nLA MATRIZ Z: ");
mostrarMatris (Z, f, c);
printf ("\n\nSUMA POR COLUMNAS DE LA MATRIS (vector A): \n");
vectorA (Z, f, c, A, c);
mostrarVector (A, c);
printf ("\n\nSUMA POR FILAS DE LA MATRIS (vector B): \n");
vectorB (Z, f, c, B, f);
mostrarVector (B, f);
getch();
}
#include <conio.h>
void llenarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
for (int j = 1 ; j <= c ; j++)
{
printf ("Inserte pos[%d][%d]: ",i,j);
scanf("%d",&M [i] [j]);
}
}
}
void mostrarMatris (int M[20][20], int f, int c)
{
for (int i = 1 ; i <= f ; i++)
{
printf ("\n");
for (int j = 1 ; j <= c ; j++)
{
printf ("[%d]",M [i] [j] );
}
}
}
void llenarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("Inserte pos.[%d]: ",i);
scanf("%d",&V [i]);
}
}
void mostrarVector (int V[20], int d)
{
for (int i = 1 ; i <= d ; i++)
{
printf ("[%d]",V [i]);
}
}
void vectorA (int M[20][20], int f, int c, int A[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int suma = 0;
for (int j = 1 ; j <= c ; j++)
{
suma = suma + M [j] [i];
}
A [i] = suma;
}
}
void vectorB (int M[20][20], int f, int c, int B[20], int d)
{
for (int i = 1 ; i <= f ; i++)
{
int suma = 0;
for (int j = 1 ; j <= c ; j++)
{
suma = suma + M [i] [j];
}
B [i] = suma;
}
}
int main ()
{
int Z [20] [20];
int A [20];
int B [20];
int f, c;
printf ("Inserte filas de la matris: ");
scanf("%d",&f);
printf ("Inserte columnas de la matris: ");
scanf("%d",&c);
printf ("\nLLENANDO MATRIS: \n");
llenarMatris (Z, f, c);
printf ("\nLA MATRIZ Z: ");
mostrarMatris (Z, f, c);
printf ("\n\nSUMA POR COLUMNAS DE LA MATRIS (vector A): \n");
vectorA (Z, f, c, A, c);
mostrarVector (A, c);
printf ("\n\nSUMA POR FILAS DE LA MATRIS (vector B): \n");
vectorB (Z, f, c, B, f);
mostrarVector (B, f);
getch();
}
0 Comentarios