Posts

Showing posts from October, 2021

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 ...

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 ]);                     }    ...

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 ; }

20.Example of array with pointer

  #include <stdio.h> int main () {     int sum = 0 ; float percentage ;     int a [ 5 ];     int * ptr = a ;     for ( int i = 0 ; i < 5 ; i ++)     {         printf ( " \n Enter the marks of subject %d :" , i + 1 );         scanf ( " %d " , ptr ); //or scanf("%d",&a[0]);         ptr ++;     }     for ( int j = 0 ; j < 5 ; j ++)     {         printf ( "The marks of subject %d is: %d \n " , j + 1 , a [ j ]);         sum = sum + a [ j ];     }     printf ( " \n Total marks= %d " , sum );     percentage = ( float )( sum * 100 )/ 500 ;     printf ( " \n Percentage= %0.2f%% " , percentage ); //%% is used to print %     return 0 ; }

19.Example of Array

  #include <stdio.h> int main () {     int sum = 0 ; float percentage ;     int a [ 5 ];     for ( int i = 0 ; i < 5 ; i ++)     {         printf ( " \n Enter the marks of subject %d :" , i + 1 );         scanf ( " %d " , & a [ i ]);     }     for ( int j = 0 ; j < 5 ; j ++)     {         printf ( "The marks of subject %d is: %d \n " , j + 1 , a [ j ]);         sum = sum + a [ j ];     }     printf ( " \n Total marks= %d " , sum );     percentage = ( float )( sum * 100 )/ 500 ;     printf ( " \n Percentage= %0.2f%% " , percentage ); //%% is used to print %     return 0 ; }

18.Return value without return keyword

  #include <stdio.h>   void sumAndavg ( int x , int y , int * sum , float * avg ) {    * sum = x + y ;    * avg =( float )( x + y )/ 2 ; } int main () {     int a , b , sum ;     float avg ;     printf ( "Enter two natural numbers :" );     scanf ( " %d %d " , & a , & b );     sumAndavg ( a , b ,& sum ,& avg );     printf ( " \n The sum is %d and average is %0.2f " , sum , avg ); //2 zeros after decimal         return 0 ; }

17.Example of call by value & call by reference

  #include <stdio.h> void swap ( int a , int b ); void swap1 ( int * a , int * b ); int main (){     int a , b ;     printf ( "Enter the value of a and b :" );     scanf ( " %d %d " ,& a ,& b );     swap ( a , b );     printf ( " \n The value of a and b after swap(wrong method) is %d and %d " , a , b );     swap1 (& a ,& b );     printf ( " \n The value of a and b after swap is %d and %d " , a , b );     return 0 ; }     void swap ( int x , int y ) //call by value     {         int temp ; //do not swap         temp = x ;         x = y ;         y = x ;     }     void swap1 ( int * x , int * y ) //call by reference     {       int temp ;         temp =* x ;         * x =* y ; ...

16.Pattern using recursion in C

  #include <stdio.h> void pattern ( int x ); int main (){     int value ;     printf ( "Enter a value :" );     scanf ( " %d " ,& value );     pattern ( value );     return 0 ; }     void pattern ( int x )     {         if ( x == 0 )         return ;         else         {             pattern ( x - 1 );             for ( int i = 1 ; i <= 2 * x - 1 ; i ++)             {                 printf ( "*" );             }             printf ( " \n " );         }     }

15.The sum of first Nth natural number using recursion

  #include <stdio.h> int natural ( int x ); int main (){     int num ;     printf ( "Enter the Nth number :" );     scanf ( " %d " ,& num );     printf ( " \n The sum of first natural number till %d is : %d " , num , natural ( num ));     return 0 ; }     int natural ( int x )     {           if ( x == 1 )         return x ;         else         return x + natural ( x - 1 );     }

14.Fibonacci series using recursion

  #include <stdio.h> int fibo ( int x ); //fibonacci series using recursion int main () {     int a ;     printf ( "Enter the Nth number :" );     scanf ( " %d " , & a );     printf ( " \n The fibonacci value of %d is: %d " , a , fibo ( a ));     return 0 ; } int fibo ( int a ) {     if ( a <= 1 )     return a ;     else     return fibo ( a - 1 )+ fibo ( a - 2 ); }

EDV Confirmation number

 20235OHJQ5TZLUEX

13.Factorial using recursion

  #include <stdio.h> int factorial ( int a ); int main (){     int a ;     printf ( "Enter a number :" );     scanf ( " %d " ,& a );     printf ( " \n The factorial of %d is : %d " , a , factorial ( a ));         return 0 ; } int factorial ( int a ) {     if ( a == 0 ||   a == 1 )     return 1 ;     else     return a * factorial ( a - 1 ); }

12.Random number Game

  #include <stdio.h> #include <stdlib.h> #include <time.h> int main () {     int num , guess , guesses = 1 ;     srand (( 0 ));     num = rand ()% 100 + 1 ;     // printf("The random number is :%d",num);     do     {         printf ( " \n Guess the random number :" );         scanf ( " %d " , & guess );         if ( guess > num )             printf ( " \n Lower number Please!" );         else if ( guess < num )             printf ( " \n Greater number Please!" );         else         {             printf ( "You take %d times to guess the number..." , guesses );         }             guesses ++;     } while ( guess !=...

11.Check prime number using do while loop

  #include <stdio.h> int main () {     int num , prime = 1 ;     int i = 2 ;     printf ( "Enter a number :" );     scanf ( " %d " , & num );     do     {         if ( num == 2 )         break ;         if ( num % i == 0 )             prime = 0 ;         i ++;     }     while ( num > i );     {         if ( prime == 0 )         {             printf ( " \n\n This is not a prime number :" );         }         else         {             printf ( " \n\n This is Prime number :" );         }     }     return 0 ; }

10.Check prime number using for loop

  #include <stdio.h> int main () {     int num , prime = 1 ;     printf ( "Enter a number :" );     scanf ( " %d " , & num );     for ( int i = 2 ; i < num ; i ++)     {         if ( num % i == 0 )             prime = 0 ;             }     if ( prime == 0 )     {         printf ( " \n\n This is not a prime number :" );     }     else     {         printf ( " \n\n This is Prime number :" );     }     return 0 ; }

9.Factorial using while loop

  #include <stdio.h> int main (){     int n , i = 1 ;     int factorial = 1 ;     printf ( "enter a number : \n " );     scanf ( " %d " ,& n );     while ( i <= n )     {     factorial = factorial * i ;     i ++;     }     printf ( "The fctorial of %d is : %d " , n , factorial );     return 0 ; }

8.Factorial using for loop

  #include <stdio.h> int main (){     int num , factorial = 1 ;     printf ( "Enter a number :" );     scanf ( " %d " ,& num );     for ( int i = 1 ; i <= num ; i ++)     {         factorial = factorial * i ;     }     printf ( " \n The factorial of %d is : %d " , num , factorial );     return 0 ; }

7.Example of continue statement

  #include <stdio.h> int main () {     int i = 0 ;     int skip = 5 ;     while ( i < 10 )     {         i ++;         if ( i != skip )         {             continue ;         }         else             printf ( " %d \n " , i );     }     return 0 ; }

6.Greater among 4 value

  #include <stdio.h> // to find greater number among four numbers int main (){     int a , b , c , d , great1 = 0 , great2 = 0 ;     printf ( "Enter any four numbers :" );     scanf ( " %d %d %d %d " ,& a ,& b ,& c ,& d );     if ( a > b )     great1 = a ;     else     great1 = b ;     if ( c > d )     great2 = c ;     else     great2 = d ;     if ( great1 > great2 )     printf ( " %d is greater \n " , great1 );     else     printf ( " %d is greater \n " , great2 );     return 0 ; }

5.incomeTax

  #include <stdio.h> int main () {     int income ;     int tax = 0 ;             printf ( "Enter your income : \n " );         scanf ( " %d " , & income );                 if ( income >= 250000 && income <= 500000 )         tax = tax + 0.05 *( income - 250000 );         if ( income >= 500000 && income <= 1000000 )         tax = tax + 0.20 *( income - 250000 );         if ( income >= 1000000 )         tax = tax + 0.30 *( income - 250000 );         printf ( "The tax you have to pay is : %d " , tax );       /*  tax = (income - 250000);     if (income <= 250000)         printf("No tax :\n");     else if (income > 250000 && income <= 500...

4.Logical operators

  #include <stdio.h> int main (){     int age , vipPass ;     printf ( "Enter your age \n " );     scanf ( " %d " ,& age );     printf ( "Enter 1 if you have vipPass: \n " );     scanf ( " %d " ,& vipPass );     if ( age >= 18 && age <= 90 || vipPass == 1 && age != 1 )     {         printf ( "You can drive \n " );     }     else     {         printf ( "You can't drive!" );     }     return 0 ; }

3.Operators in C

  #include <stdio.h> #include <math.h> int main (){     int a , b ;     printf ( "Enter the first value:" );     scanf ( " %d " ,& a );     printf ( "Enter the second value:" );     scanf ( " %d " ,& b );     printf ( "The addition is: %d \n " , a + b );     printf ( "The subtraction is: %d \n " , a - b );     printf ( "The multiplication is: %d \n " , a * b );     printf ( "The division is: %d \n " , a / b );     printf ( "The remainder of 8 divided by 5 is : %d \n " , 8 % 5 );     // how to calculate the power     printf ( "The value of 4 to the power 5 is %f " , pow ( 4 , 5 ));     return 0 ; }

2.How to find the area of rectangle

  #include <stdio.h> #include <conio.h> // How to find Area of rectangle int main () {     float length , breadth ;     printf ( "Enter the lenght: \n " );     scanf ( " %f " , & length );         printf ( "Enter the breadth: \n " );     scanf ( " %f " , & breadth );     printf ( "The area of rectangle is: %f " , length * breadth );     return 0 ; }

1.First programming in C

  stdio .h> int main () {     int a= 4 ;     float b= 5.7 ;     // char c="a";     printf ( "the value of a is %d \n " ,a);     printf ( "The value of b is %f \n " ,b);     // printf("The value of c is %c",c);     // printf("Hello World");     return 0 ; }