Swap two number using bitwise operation, Addition of two matrices using c language

Swap two number using bitwise operation, Addition of two matrices using c language

Swap two numbers using bitwise operators 

#include <stdio.h>
int main()
{
 int num1,num2;
 printf(“Enter num1n”);
 scanf(“%d”,&num1);
 printf(“Enter num2n”);
 scanf(“%d”,&num2);
 printf(“Before Swapping Number 1= %d,Number 2= %dn”,num1,num2);
 num1=num1^num2;
 num2=num1^num2;
 num1=num1^num2;
 printf(“x=%dn”,num1);
 printf(“After Swapping Number 1= %d,Number 2= %dn”,num1,num2);
 return 0;
}

Addition of two Matrices using C language

 
#include<stdio.h>
main()
{
 int i,j,rows,col;
 printf(“Enter number of rowsn”);
 scanf(“%d”,&rows);
 printf(“Enter number of columnsn”);
 scanf(“%d”,&col);
 int a1[rows][col],a2[rows][col],add[rows][col];
 //Taking input for 1st matrix printf(“Enter Matrix 1n”);
 for(i=0;i<rows;i++) 
{
 for(j=0;j<col;j++) 
{
 scanf(“%d”,&a1[i][j]);
}
}
 //Taking input for 2nd matrix printf(“Enter Matrix 2n”);
 for(i=0;i<rows;i++) 
{
 for(j=0;j<col;j++) 
{
 scanf(“%d”,&a2[i][j]);
}
}
 //Addition of matrix for(i=0;i<rows;i++) 
{
 for(j=0;j<col;j++) 
{
 add[i][j]=a1[i][j]+a2[i][j];
}
}
 printf(“Addition of above matrices isn”);
 for(i=0;i<rows;i++) 
{
 for(j=0;j<col;j++) 
{
 printf(“%dt”,add[i][j]);
}
 printf(“n”);
}
 
}

Leave a Comment

error: Content is protected !!