Skip to main content

Posts

Showing posts from April, 2017

WAP to multiplication of two 2x2 matrix.

//WAP to multiplication of two 2x2 matrix. #include <stdio.h> #include <conio.h> void main() { int i,j,k,a[2][2],b[2][2],c[2][2],sum; clrscr(); printf( "Enter any element of 1st matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&a[i][j]); } printf( "Entre any element of 2nd matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&b[i][j]); } //Multiplication logic for (i=0;i<2;i++) { sum=0; for (k=0;k<2;k++) { sum = sum + a[i][k] * b[i][j]; c[i][j]=sum; } } printf( "Result matrix:" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) printf( "%d\t" ,c[i][j]); printf( "\n" ); } getch(); }

WAP to read element of two 2x2 matrix and perform addition

//WAP to read element of two 2x2 matrix and perform addition #include <stdio.h> #include <conio.h> void main() { int i,j,a[2][2],b[2][2],c[2][2]; clrscr(); printf( "Enter any element of 1st matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&a[i][j]); } printf( "Entre any element of 2nd matrix:\n" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) scanf( "%d" ,&b[i][j]); } for (i=0;i<2;i++) { for (j=0;j<2;j++) c[i][j]=a[i][j]+b[i][j]; } printf( "Element of Result matrix:" ); for (i=0;i<2;i++) { for (j=0;j<2;j++) printf( "%d\t" ,c[i][j]); } getch(); }

WAP to ask n number from user sort them in assending order and display

//WAP to ask n number from user sort them in assending order and display #include <stdio.h> #include <conio.h> void main() { int i,j,n,num[100],temp; clrscr(); printf( "Enter any value of n:\n" ); scanf( "%d" ,&n); printf( "Entre any value in array:\n" ); scanf( "%d" ,&num[i]); for (i=0;i<n;i++) scanf( "%d" ,&num[i]); for (i=0;i<n;i++) { for (j=i+1;j<n;j++) { if (num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf( "Sorting element of array:" ); for (i=0;i<n;i++) printf( "%d" ,num[i]); getch(); }

WAP to input n number in array & find largest number

//WAP to input n number in array & find largest number #include <stdio.h> #include <conio.h> void main() { int i,num[100],g,n; clrscr(); printf( "Enter any value of n:\n" ); scanf( "%d" ,&n); printf( "Entre any value in array:\n" ); scanf( "%d" ,&num[i]); for (i=0;i<n;i++) scanf( "%d" ,&num[i]); g=num[0]; for (i=0;i<n;i++) { if (num[i]>g) g=num[i]; } printf( "Greater num = %d" ,g); getch(); }

WAP to input 30 number in array & count how many are even and how many are odd.

//WAP to input 30 number in array & count how many are even and how many are odd. #include <stdio.h> #include <conio.h> void main() { int i,num[30],ec=0,oc=0; clrscr(); printf( "Enter value in array:\n" ); for (i=0;i<30;i++) scanf( "%d" ,&num[i]); for (i=0;i<30;i++) { if (num[i]%2==0) ec++; else oc++; } printf( "No of even = %d" ,ec); printf( "No of odd = %d" ,oc); getch(); }