Full width home advertisement

HTML

Tech News

Ad

 Arrays and string Handling

Practical 2.
Write a c program to display two matrix on screen and perforn the addition of two matrix and print on screen.

#include <stdio.h>
#include <conio.h>

void main()
{
	int i, j, a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
	int c[3][3], b[3][3] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
	clrscr();
	printf("First arry\n");
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d", a[i][j]);
		}
		printf("\n");
	}
	printf("\n\nSecond arry\n");
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d", b[i][j]);
		}
		printf("\n");
	}
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			c[i][j] = a[i][j] + b[i][j];
		}
	}
	printf("\n\nthe addition of given matrices: \n");
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			printf("%d", c[i][j]);
		}
		printf("\n");
	}
	getch();
}

Thank you for visiting seeya again

No comments:

Post a Comment

Bottom Ad [Post Page]