Monday, November 23, 2009

some extereme helpfull c program n notes



/*** Program to Print Transpose of a Matrix ***/


#include


main()
{
int a[10][10], i, j, row, col;


printf("\nEnter no. of rows & columns: ");
scanf("%d %d", &row, &col);


printf("\nEnter elements of Matrix:\n");
for (i=0; i for (j=0; jscanf("%d", &a[i][j]);


printf("\n\nElements of Matrix:\n\n");
for (i=0; i {
for (j=0; jprintf("\t%d", a[i][j]);
printf("\n\n");
}


printf("\n\nTranspose of Matrix:\n\n");
for (i=0; i {
for (j=0; jprintf("\t%d", a[j][i]);
printf("\n\n");
}


getch();
}


program to multiply to matrix

#include


void main()
{
int a[10][10], b[10][10], c[10][10], i, j, k, r1, r2, c1, c2;


back:
printf("\nEnter no. of rows and columns of Matrix A: ");
scanf("%d %d", &r1, &c1);
printf("\nEnter no. of rows and columns of Matrix B: ");
scanf("%d %d", &r2, &c2);


if (c1 != r2)
{
printf("\n\nMultiplication is not possible\n");
goto back;
}


printf("\n\nEnter elements of Matrix A:\n");
for (i=0; i for (j=0; jscanf("%d", &a[i][j]);


printf("\nEnter elements of Matrix B:\n");
for (i=0; i for (j=0; jscanf("%d", &b[i][j]);


printf("\n\nElements of Matrix A:\n\n");
for (i=0; i {
for (j=0; jprintf("\t%d", a[i][j]);
printf("\n\n");
}


printf("\n\nElements of Matrix B:\n");
for (i=0; i {
for (j=0; jprintf("\t%d", b[i][j]);
printf("\n\n");
}


for (i=0; i for (j=0; j {
c[i][j] = 0;
for (k=0; kc[i][j] = c[i][j] + a[i][k] * b[k][j];
}


printf("\n\nMultiplication of Matrices:\n\n");
for (i=0; i {
for (j=0; jprintf("\t%d", c[i][j]);
printf("\n\n");
}


getch();
}

perfect no check

void main()
{
int i,no,sum=0;

clrscr();

printf("Enter no : ");
scanf("%d",&no);

for (i=1; i {
if (no%i==0)
sum=sum+i;
}

if (no==sum)
printf("\n %d is a Perfect Number",no);
else
printf("\n %d is not a Perfect Number",no);

getch();
}