Showing posts with label Arithmetic operators. Show all posts
Showing posts with label Arithmetic operators. Show all posts

Friday, 24 May 2013

Multiplication of two matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],mul[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\nMultiplication of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
mul[i][j]=a[i][j]*b[i][j];
printf("\na[%d][%d] = %d ",i,j,mul[i][j]);

}
printf("\n");
}

getch();
}

Diffference of two matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],diff[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\ndiffrence of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
diff[i][j]=a[i][j]-b[i][j];
printf("\na[%d][%d] = %d ",i,j,diff[i][j]);

}
printf("\n");
}

getch();
}

Addition of two Matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[3][3],b[3][3],sum[3][3];
printf("Enter the elements of array A\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
printf("\n");
}

printf("\nEnter the elements of array B\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array A are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,a[i][j]);
}
printf("\n");
}

printf("\n\nThe elements of array B are\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("\na[%d][%d] = %d ",i,j,b[i][j]);
}
printf("\n");
}


printf("\n\nSum of two matrices is\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sum[i][j]=a[i][j]+b[i][j];
printf("\na[%d][%d] = %d ",i,j,sum[i][j]);

}
printf("\n");
}

getch();
}
                               

Thursday, 16 May 2013

Calculate number of students having marks more than 60


#include<stdio.h>
#include<conio.h>
void main()
{
int marks[10],i,n=0,m;
clrscr();
printf("CALCULATE NUMBER OF STUDENTS HAVING MARKS >60");

for(i=0;i<=9;i++)
{
printf("\nEnter marks of student number %d",i+1);
scanf("%d",&marks[i]);
}
for(i=0;i<=9;i++)
{
if(marks[i]>60)
{
n++;
}
}
printf("\nNumber of students having marks more than 60 are : %d",n);
getch();
}

Find average of two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,average;
cout<<"Enter two numbers";
cin>>a>>b;
average=(a+b)/2;
cout<<"\n Average of two numbers is"<<average;
getch();
}

Wednesday, 15 May 2013

Swapping value of two variables without third variable


#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cout<<"enter the value of a";
cin>>a;
cout<<"\n Enter b";
cin>>b;  
a=a+b;  
b=a+b;  

a=b-a;    
b=-1*(a-b)-a;

cout<<"\n a is"<<a;
cout<<"\n b is"<<b;
getch();
}

full details in json
Proudly Powered by Blogger.