Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int *MatrizA;
- int *MatrizB;
- int primo();
- int primo1();
- void menu();
- void suma(int *x, int *y, int a);
- int r[]={0};
- int h[]={0};
- void resta(int *x, int *y, int a);
- void imprimir(int *x, int a);
- int main()
- {
- int M, A, i, x=0, y=0, op;
- printf("Ingresa el numero de renglones por columnas:");
- scanf("%i",&M); //columna
- A=M*M;
- //RESERVACION DE A
- MatrizA=(float **)malloc(A*sizeof(int*));
- for(i=0;i<=A-1;i++){
- MatrizA[i]=(float *)malloc(A*sizeof(int));
- }
- // MatrizB=(int*)malloc(A*sizeof(int));
- MatrizB=(float **)malloc(A*sizeof(int*));
- for(i=0;i<=A-1;i++){
- MatrizB[i]=(float *)malloc(A*sizeof(int));
- }
- menu();
- scanf("%i",&op);
- //LLENADO DE LAS MATRICES
- //MATRIZ A
- for(i=0;i<A+1;i++){
- x=primo1();
- MatrizA[i]= x;
- }
- //MATRIZ B
- for(i=0;i<A+1;i++){
- y=primo1();
- MatrizB[i] = y;
- }
- switch(op){
- case 1:
- printf("SUMA");
- suma(MatrizA,MatrizB,A);
- imprimir(r,A);
- break;
- case 2:
- printf("RESTA:");
- resta(MatrizA,MatrizB,A);
- imprimir(h,A);
- break;
- case 3:
- printf("MULTIPLICACIÓN:\n");
- break;
- case 4:
- imprimir(MatrizA,A);
- imprimir(MatrizB,A);
- break;
- }
- }
- int primo1(){
- int x;
- srand(time(NULL));
- do{x=rand()%(101);
- if(x%2!=0 && x%3!=0 && x%5!=0 && x%7!=0){
- if (x==2 || x==3 || x==5 || x==7){
- return x;
- }
- }
- else{
- x=0;
- }
- }while(x==0);
- return x;
- }
- int primo(){
- int x, a;
- srand(time(NULL));
- a=rand()%(1-27);
- switch(a){
- case 1:
- x=2;
- return x;
- break;
- case 2:
- x=3;
- return x;
- break;
- case 3:
- x=5;
- return x;
- break;
- case 4:
- x=7;
- return x;
- break;
- case 5:
- x=11;
- return x;
- break;
- case 6:
- x=13;
- return x;
- break;
- case 7:
- x=17;
- return x;
- break;
- case 8:
- x=19;
- return x;
- break;
- case 9:
- x=23;
- return x;
- break;
- case 10:
- x=29;
- return x;
- break;
- case 11:
- x=31;
- return x;
- break;
- case 12:
- x=37;
- return x;
- break;
- case 13:
- x=41;
- return x;
- break;
- case 14:
- x=43;
- return x;
- case 15:
- x=47;
- return x;
- break;
- case 16:
- x=53;
- return x;
- break;
- case 17:
- x=59;
- return x;
- break;
- case 18:
- x=61;
- return x;
- break;
- case 19:
- x=67;
- return x;
- break;
- case 20:
- x=67;
- return x;
- break;
- case 21:
- x=71;
- return x;
- break;
- case 22:
- x=73;
- return x;
- break;
- case 23:
- x=79;
- return x;
- break;
- case 24:
- x=83;
- return x;
- break;
- case 25:
- x=89;
- return x;
- break;
- case 26:
- x=97;
- return x;
- break;
- }
- return 0;
- }
- void imprimir(int *x, int a){
- int i;
- for(i=1;i<=a;i++){
- printf("\nVector[%i]=%i\n",i, x[i]);
- }
- }
- void menu(){
- printf("\t MENÚ \n");
- printf("1.- SUMA.\n");
- printf("2.- RESTA\n");
- printf("3.- MULTIPLICACIÓN.\n");
- printf("4.- Imprimir tus matrices.\n");
- }
- void suma(int *x, int *y, int a){
- int q;
- for(q=0; q<=a;q++){
- r[q]=*x++ + *y++;
- }
- }
- void resta(int *x, int *y, int a){
- int q;
- for (q=0;q<=a;q++){
- h[q]=*x++ - *y++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement