Showing posts with label addition of two matrix in c program. Show all posts
Showing posts with label addition of two matrix in c program. Show all posts

Saturday, June 16, 2012

59. Program to check whether an entered number is zero,positive,or negative


//Program to check whether an entered number is zero,positive,or negative
 #include<conio.h>
 #include<stdio.h>
 void main()
 {
  int n;
  char ch='y';
  do
  {
   fflush(stdin);
   printf("\n\nENTER THE NUMBER=");
   scanf("%d",&n);
   if(n>0)
   printf("\n\n%d IS A POSITIVE NUMBER ",n);
   if(n<0)
   printf("\n\n%d IS A NEGATIVE NUMBER ",n);
   if(n==0)
   printf("\n\n%d IS A ZERO NUMBER ",n);
   printf("\n\nDO YOU WANT TO CONTINUE?:- ");
   scanf("%s",&ch);
  }while(ch=='y'||ch=='Y');
   getch();
 }
/********************************************************************
 OUTPUT
 ********************************************************************


 3 IS A POSITIVE NUMBER

 DO YOU WANT TO CONTINUE?:- y


 ENTER THE NUMBER=5


 5 IS A POSITIVE NUMBER

 DO YOU WANT TO CONTINUE?:- y


 ENTER THE NUMBER=4


 4 IS A POSITIVE NUMBER

 DO YOU WANT TO CONTINUE?:- y


 ENTER THE NUMBER=4


 4 IS A POSITIVE NUMBER

 DO YOU WANT TO CONTINUE?:- y


 ENTER THE NUMBER=-3


 -3 IS A NEGATIVE NUMBER

 DO YOU WANT TO CONTINUE?:- y


 ENTER THE NUMBER=0


 0 IS A ZERO NUMBER

 DO YOU WANT TO CONTINUE?:-
 n
*/

Saturday, August 6, 2011

//Program to show Multiplication,Addition and Subtraction in Matices

#include<stdio.h>
#include<conio.h>
main()
{ int i,j,r1,c1,r2,c2,k,a[30][30],b[30][30],c[30][30];
clrscr();
printf("\n\nEnter the no. of rows and columns for first matrix:\n\n");
scanf("%d%d",&r1,&c1);

printf("\n\nEnter %d elements:\n",r1*c1);
for(i=0 ; i<r1 ; i++)
{ for(j=0 ; j<c1 ; j++)
{ scanf("%d",&a[i][j]);
}
}

printf("\n\nThe first matrix is:\n\n");
for(i=0 ; i<r1 ; i++)
{ for(j=0 ; j<c1 ; j++)
{ printf("%d",a[i][j]);
printf(" ");
}
printf("\n");
}

printf("\n\nEnter the no. of rows and columns for Second matrix:\n\n");
scanf("%d%d",&r2,&c2);

printf("\n\nEnter %d elements:\n",r2*c2);
for(i=0 ; i<r2 ; i++)
{ for(j=0 ; j<c2 ; j++)
{ scanf("%d",&b[i][j]);
}
}javascript:void(0)

printf("\n\nThe Second matrix is:\n\n");
for(i=0 ; i<r2 ; i++)
{ for(j=0 ; j<c2 ; j++)
{ printf("%d",b[i][j]);
printf(" ");
}
printf("\n");
}

if ((r1 == c1) && (r2 == c2))
{ printf("\n\n\nAfter adding 2 matrices the matrix will be:\n");
for(i=0 ; i<r1 ; i++)
{ for(j=0 ; j<c1 ; j++)
{ c[i][j] = a[i][j] + b[i][j];
printf("\n\t%d + %d = %d",a[i][j],b[i][j],c[i][j]);
printf(" ");
}
}
}
else
{ printf("\n\nAddition is not possible");
}


if ((r1 == c1) && (r2 == c2))
{ printf("\n\n\nAfter subtracting 2 matrices the matrix will be:\n");

for(i=0 ; i<r1 ; i++)
{ for(j=0 ; j<c1 ; j++)
{ c[i][j] = a[i][j] - b[i][j];
printf("\n\t%d - %d = %d",a[i][j],b[i][j],c[i][j]);
printf(" ");
}
}
}
else
{ printf("\n\nSubtraction is not possible");
}

if (r2 == c1)
{ printf("\n\n\nAfter multiplying 2 matrices the matrix will be:\n");

for(i=0 ; i<r1 ; i++)
{ printf("\n");
for(j=0 ; j<c2 ; j++)
{ c[i][j] = 0;
for(k=0 ; k<r1 ; k++)
{ c[i][j] = c[i][j] + (a[i][k] * b[k][j]);
}
printf("\t%d ",c[i][j]);
}
printf("\n");
}
}
else
{ printf("\n\nMultiplication is not possible");
}
getch();
}

Programming the Whole World!