Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 10
- int introducir_datos(int x[N][N]);
- int contar(int x[N][N]);
- void ver_matriz(int x[N][N]);
- int substituir(int x[N][N]);
- int gestion(int x[N][N]){
- int opcion;
- do{
- printf("\n1- Introducir dato\n2- Contar numeros positivos, negativos o ceros\n3- Ver matriz\n4- Cambiar por"
- " matriz identidad\n5- Salir\nSeleccione una opcion:\n");
- scanf("%d",&opcion);
- switch (opcion){
- case 1: introducir_datos(x);
- break;
- case 2: contar(x);
- break;
- case 3: ver_matriz(x);
- break;
- case 4: substituir(x);
- break;
- }
- } while (opcion != 5);
- return 0;
- }
- int introducir_datos(int x[N][N]){
- int i,j;
- printf("Introduce fila:\n");
- scanf("%d",&i);
- printf("Introduce columna:\n");
- scanf("%d",&j);
- printf("Introduce un valor:\n");
- scanf("%d",&x[i-1][j-1]);
- return x[i-1][j-1];
- }
- int contar(int x[N][N]){
- int opcion2,pos = 0, neg = 0, zero = 0;
- do {
- printf("\n21- Contar positivos\n22- Contar negativos\n23- Contar ceros\n24-Volver atrás\nSeleccione:\n");
- scanf("%d",&opcion2);
- switch (opcion2){
- case 21: for (int i = 0; i < N; i++){
- for(int j = 0; j < N; j++){
- if (x[i][j] > 0){
- pos++;
- }
- }
- }
- printf("Hay %d positivos",pos);
- break;
- case 22: for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- if(x[i][j] < 0){
- neg++;
- }
- }
- }
- printf("Hay %d negativos\n",neg);
- break;
- case 23: for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- if(x[i][j] == 0){
- zero++;
- }
- }
- }
- printf("Hay %d ceros",zero);
- break;
- }
- } while (opcion2 != 24);
- return 0;
- }
- void ver_matriz(int x[N][N]){
- for (int i = 0; i < N; i++){
- for (int j = 0; j< N; j++){
- printf("%d\t",x[i][j]);
- } printf("\n");
- }
- }
- int substituir(int x[N][N]){
- for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- if (i == j){
- x[i][j] = 1;
- } else{
- x[i][j] = 0;
- }
- }
- }
- }
- int main(){
- int mat[N][N];
- for (int i = 0; i < N ; i++){
- for (int j = 0; j < N; j++){
- mat[i][j] = 0;
- }
- }
- gestion(mat);
- }
Add Comment
Please, Sign In to add comment