my code stock.com

Programa 40 en c

Snippet options

Download: Download snippet as periferia-20.c.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include<stdio.h>
#include<windows.h>
 
#define MAXSIZE 50
 
void leermatriz(int matriz[MAXSIZE][MAXSIZE], int *nfilas, int *ncolumnas);
void imprimirmatriz(int matriz[MAXSIZE][MAXSIZE], int nfilas, int ncolumnas);
void suma(int matriz[MAXSIZE][MAXSIZE], int nfilas, int ncolumnas);
 
int main()
{
	int matriz[MAXSIZE][MAXSIZE];
	int filas, columnas;
 
	system("Color 4b");
	printf("\nPrograma que imprima la suma de la periferia de una matriz");
	leermatriz(matriz, &filas, &columnas);
	imprimirmatriz(matriz, filas, columnas);
	suma(matriz, filas, columnas);
	}
 
void leermatriz(int matriz[MAXSIZE][MAXSIZE], int *nfilas, int *ncolumnas)
{
	int i,j;
 
	printf("\nLectura de matriz");
	do{
		printf("\nDame la cantidad de fila=>");
		scanf("%d", nfilas);
		printf("Dame la cantidad de columnas=>");
		scanf("%d", ncolumnas);
		if(*nfilas != *ncolumnas){
			printf("\nNumero de filas debe ser igual al de columnas");
		}
		if (*nfilas > MAXSIZE || *ncolumnas > MAXSIZE){
			printf ("\nNumero de filas y de columnas no pueden ser mayor de %d",MAXSIZE);
		}
	}while(*nfilas != *ncolumnas || *nfilas > MAXSIZE || *ncolumnas > MAXSIZE);
 
	for(i = 0; i < *nfilas; i++){
		for(j = 0; j < *ncolumnas; j++){
			printf("\nDame el valor de la casilla[%d][%d]", i, j);
			scanf("%d", &matriz[i][j]);
			}
	}
	system("pause");
}
 
void imprimirmatriz(int matriz[MAXSIZE][MAXSIZE], int nfilas, int ncolumnas)
{
	int i,j;
 
	for(i = 0; i < nfilas; i++){
		printf("\n");
		for(j = 0; j < ncolumnas; j++){
			system("color e");
			printf("\t%d", matriz[i][j]);
		}
	}
	system("pause");
}
 
void suma(int matriz[MAXSIZE][MAXSIZE], int nfilas, int ncolumnas)
{
	int i, j;
	int sumaperiferia = 0;
 
	for(i = 0; i < nfilas; ++i){
		for(j = 0; j < ncolumnas; ++j){
			if(i == 0 || i == nfilas - 1 || j == 0 || j == ncolumnas - 1){
				sumaperiferia += matriz[i][j];
			}
		}
	}
	printf("\nLa suma de los elementos de la periferia es:%d", sumaperiferia);
   system("pause");
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.