Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 3
- void matriz(int x[N][N]);
- void matriz(int x[N][N]){
- printf("Dame la matriz: \n");
- for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- scanf("%d",&x[i][j]);
- }
- }
- for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- printf("%d\t",x[i][j]);
- } printf("\n");
- }
- }
- void cambio(int x[N][N]){
- int i,j;
- printf("\nSeleccione fila:\n");
- scanf("%d",&i);
- printf("\nSeleccione columna:\n");
- scanf("%d",&j);
- printf("Introduce cifra:\n");
- scanf("%d",&x[i-1][j-1]);
- }
- void cuenta_impar(int x[N][N]){
- int impares = 0;
- for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- if(x[i][j] % 2 != 0){
- impares++;
- }
- }
- } printf("\nHay %d impares\n",impares);
- }
- int main(){
- int opcion,opcion2,x[N][N];
- matriz(x);
- do{
- printf("1- Cambiar elemento\n2- Contar impares\n3- Ver matriz\n4- Salir\nSeleccione una opcion:\n");
- scanf("%d",&opcion);
- switch (opcion){
- case 1: cambio(x);
- break;
- case 2: cuenta_impar(x);
- break;
- case 3: for (int i = 0; i < N; i++){
- for (int j = 0; j < N; j++){
- printf("%d\t",x[i][j]);
- } printf("\n");
- }
- break;
- case 5: do {
- printf("\t1- Volver atrás:\n");
- scanf("%d",&opcion2);
- } while (opcion2 != 1);
- break;
- }
- } while (opcion != 4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment