Posts

C program to Convert Decimal to Hexadecimal

  1 /* Write a program to convert a decimal number to its 2 equivalent hexadecimal number. */ 3 4 #include <stdio.h> 5 main() 6 { 7 unsigned long dec; 8 int a[ 25 ],c= 0 ,i; 9 clrscr(); 10 printf( "\nENTER A DECIMAL NUMBER: " ); 11 scanf( "%lu" ,&dec); 12 printf( "\n%lu IN HEXADECIMAL FORMAT: " ,dec); 13 while (dec> 0 ) 14 { 15 a[c]=dec% 16 ; 16 dec=dec/ 16 ; 17 c++; 18 } 19 for (i=c- 1 ;i>= 0 ;i--) 20 { 21 if (a[i]>= 10 ) 22 printf( "%c" ,a[i]+ 55 ); 23 else 24 printf( "%d" ,a[i]); 25 } 26 getch(); 27 }}

C Program to Multiply Two Matrix

  #include <stdio.h> #include <stdlib.h> #include <string.h> int main (){ // Initialising 1st Matrix system ( "clear" ); int m1 , n1 , m2 , n2 ; printf ( "No of Rows of 1st Matrix : " ); scanf ( " %d " , & m1 ); printf ( "No of Columns of 1st Matrix : " ); scanf ( " %d " , & n1 ); // Initialising the 2nd Matrix printf ( "No of Rows of 2nd Matrix : " ); scanf ( " %d " , & m2 ); printf ( "No of Columns of 2nd Matrix : " ); scanf ( " %d " , & n2 ); if ( n1 != m2 ) { printf ( "Can't Compute ... \n " ); // Checking n1=m2 } else { int matrix1 [ m1 ][ n1 ]; int matrix2 [ m2 ][ n2 ]; // Taking input of 1st Matrix printf ( " \n " ); printf ( "Enter the 1st Matrix : \n\n " ); for ( int i ...

C Program to Add two Matrix

  #include <stdio.h> #include <stdlib.h> int main (){ int m , n ; system ( "clear" ); printf ( "Enter the number of Rows : " ); scanf ( " %d " , & m ); printf ( "Enter the Number of Columns :" ); scanf ( " %d " , & n ); int arr_1 [ m ][ n ], arr_2 [ m ][ n ]; printf ( " \n First Matrix: \n " ); // Taking input of First Matrix . . . for ( int i = 0 ; i < m ; i ++ ){ for ( int j = 0 ; j < n ; j ++ ){ printf ( "a[ %d ][ %d ]" , i + 1 , j + 1 ); scanf ( " %d " , & arr_1 [ i ][ j ]); } } printf ( " \n Second Matrix: \n " ); // Taking input of Third Matrix . . . for ( int i = 0 ; i < m ; i ++ ){ for ( int j = 0 ; j < n ; j ++ ){ printf ( "b[ %d ][ %d ]" , i + 1 , j + 1 ); scanf ( " %d " , & arr_2 [ i ][ j ]); } } printf ( ...

C Program to print Fibonacci sequence

  #include <stdio.h> #include <stdlib.h> int main () { system ( "clear" ); int n , i ; printf ( "Enter how many digits you want to print :" ); scanf ( " %d " , & n ); int array [ 100 ]; array [ 0 ] = 0 , array [ 1 ] = 1 ; for ( i = 0 ; i <= n - 2 ; i ++ ) { array [ i + 2 ] = array [ i ] + array [ i + 1 ]; } printf ( "{ " ); for ( i = 0 ; i < n ; i ++ ) { printf ( " %d\t " , array [ i ]); } printf ( " } \n " ); }

C program to convert decimal to Binary

  #include <stdio.h> #include <stdlib.h> int main (){ system ( "clear" ); int decimal = 0 , arr [ 50 ] = { 0 }, remainder = 0 ; printf ( "Enter the Decimal Digit :" ); scanf ( " %d " , & decimal ); static int i ; for ( i = 0 ; i <= 50 ; i ++ ) { if ( decimal >= 2 ) { remainder = decimal % 2 ; arr [ i ] = remainder ; decimal = decimal / 2 ; } else { arr [ i ] = decimal ; break ; } } for ( i ; i >= 0 ; i -- ){ printf ( " %d " , arr [ i ]); } }