Posts

27. Array Operation(insertion/deletion) in C

  #include <stdio.h> int main (){     int arr [ 10 ];     int insertValue ;     int position ;     int size ;     printf ( "Enter the size of array: \n " );     scanf ( " %d " ,& size );     if ( size > 10 )     {         printf ( "Memory Overflow" );     }     else     {         printf ( "Enter the array value :" );         for ( int i = 0 ; i < size ; i ++)     {         scanf ( " %d " ,& arr [ i ]);     }     printf ( " \n The values of array are : \n " ); //traversal     for ( int i = 0 ; i < size ; i ++)     {         printf ( " %d |" , arr [ i ]);     }     //insert any value in between unsorted array       printf ( " \n Enter the position of array at which you wanted to insert : \n " );     scanf ( " %d " ,& position );     printf ( " \n Enter the value u wanted to insert in the array : \n " );     scanf ( " %d " ,& insertValue );  

26.Encrypt/Decrypt string

  #include <stdio.h> void encrypt ( char * a ) {     while (* a != ' \0 ' )     {         * a =* a + 1 ;         a ++;     } } void decrypt ( char * c ) {     while (* c != ' \0 ' )     {         * c =* c - 1 ;         * c ++;     } } int main (){     char str [] = "hi bro how are you" ;     encrypt ( str );     printf ( "Encrypted string is : %s " , str );     decrypt ( str );     printf ( " \n Decrypted string is : %s " , str );     return 0 ; }

25.Printing the table using Array and Function call taking input from user

  #include <stdio.h> void mul ( int * a , int value , int col ) {     printf ( "The multi[lication table of %d : is \n " , value );     for ( int i = 0 ; i < col ; i ++)     {         a [ i ] = value * ( i + 1 );     }     for ( int i = 0 ; i < col ; i ++)     {         printf ( " %d X %d = %d \n\n " , value , i + 1 , a [ i ]);     }     // printf("******************************************\n"); } int main () {     int rows , coloumns ;     int value ;     printf ( "Enter the size of row and coloumn :" );     scanf ( " %d%d " , & rows , & coloumns );     int arr [ rows ][ coloumns ];     for ( int i = 0 ; i < rows ; i ++)     {         printf ( " \n Enter the vaule :" );         scanf ( " %d " , & value );         mul ( arr [ i ], value , coloumns );     }     return 0 ; }

24.Count positive integer in Array

  #include <stdio.h> int main (){     int count = 0 ;     int arr [ 10 ];     printf ( "Enter 10 integers \n :" );     for ( int i = 0 ; i < 10 ; i ++)     {         scanf ( " %d " ,& arr [ i ]);         if ( arr [ i ]> 0 )         { count ++;}     }     printf ( "Total positive integers are : %d " , count );     return 0 ; }

23.Reverse Array

  #include <stdio.h> void reverseArr ( int arr [] , int b ); int main () {     int arr [] = { 1 , 2 , 3 , 4 , 5 };     int n = 5 ;     reverseArr ( arr , n );     for ( int i = 0 ; i < 5 ; i ++)     printf ( " %d \n " , arr [ i ]);     return 0 ; } void reverseArr ( int arr [ 0 ], int n ) {     for ( int i = 0 ; i < n / 2 ; i ++)     {         int temp ;         temp = arr [ i ];         arr [ i ] = arr [ n - i - 1 ];         arr [ n - i - 1 ]= temp ;     } }

22.Multidimensional array(2D)

#include <stdio.h> int main (){     int n_students = 3 ;     int n_subjects = 5 ;     int arr [ 3 ][ 5 ];     for ( int i = 0 ; i < n_students ; i ++)     {         for ( int j = 0 ; j < n_subjects ; j ++)         {             printf ( "Enter the marks of student %d of subject %d \n " , i + 1 , j + 1 );             scanf ( " %d " ,& arr [ i ][ j ]);         }     }             for ( int i = 0 ; i < n_students ; i ++)     {         for ( int j = 0 ; j < n_subjects ; j ++)         {             printf ( "The marks of student %d of subject %d is %d \n " , i + 1 , j + 1 , arr [ i ][ j ]);                     }     }     return 0 ; }  

21.Array to function

  #include <stdio.h> void arrFunc ( int * a , int n ) {     for ( int i = 1 ; i <= n ; i ++)     {     printf ( "The value of %d is %d \n " , i ,* a );     a ++;     } } int main () {     //array to function     int arr [ 6 ] = { 2 , 5 , 4 , 35 , 7 , 8 };     arrFunc ( arr , 6 );     return 0 ; }