Search This Blog


Friday, October 18, 2019

Practice program on function

View chapters from top of the tab for more information.

Subscribe my youtube channel, link is given below.

click on this ⇒⇒A step Up

c language by a step up
Practice program on function


P1. Program to input any no. after that find sum of all digit by function .


#include<stdio.h>
#inclued<conio.h>
 void findsum_digit();
 void main()
  {
   clrscr();
   findsum_digit();
  getch();
  }
void findsum_digit()
  {
   int a , d , sum = 0 ;
   printf( “ Enter the no. ” );
   scanf( “ %d “, &a );
  while ( a > 0 )
   {
    d = a % 10 ;
    sum = sum + d;
    a= a/10;
   }
 printf( “ Sum of all the digits are = %d “, sum );
  }

P2. Program to input length and breadth after that find area and perimeter of rectangle by function .


#include<stdio.h>
#inclued<conio.h>
 void input();
 void findarea();
 void findperi();
 int l , b ;
 void main()
  {
   clrscr();
   input();
   findarea();
   findperi();
  getch();
  }
void input()
  {
   printf( “ Enter the length and breadth  ” );
   scanf( “  %d  %d  “, &l , &b  );
  }
void findarea()
  {
   int ar ;
   ar = l * b ;
    printf( “ Area of the rectangle = %d \n “ , ar );
   }
void findperi()
   {
   int peri ;
   peri = 2 * ( l + b );
   printf( “ Perimeter of rectangle = %d “ , peri ) ;
  }

P3. Program to input any no. after that print the table by implementing extra function.


#include<stdio.h>
#inclued<conio.h>
 void input();
 void table();
 int n ;
  void main()
  {
   clrscr();
   input();
    findtable();
  getch();
  }
void input()
  {
   printf( “ Enter the length and breadth  ” );
   scanf( “  %d  %d  “, &l , &b  );
  }
void table()
  {
   int i , table ;
   for ( i = 1 ; i <= 10 ; i ++ )
  {
   table = n * i ;
   printf ( “ table = %d “ , table );
  }
 }

P4. Program to create a function as named findsmallest and to input three no.  as parameter after that find smallest no.


#include<stdio.h>
#inclued<conio.h>
 void findsmallest( int , int , int );
 void main()
  {
   clrscr();
   findsmallest ( 20 , 30 , 5 ) ;
   getch();
  }
void findsmallest ( int a , int b , int c )
   {
    int smt ;
    smt = a < b && a < c ? a : ( b < c ? b : c ) ;
    printf ( “ smallest no. = %d “ , smt ) ;
  }


One more process to access parameter


 void main ()
  {
     clrscr ();
     int a , b , c ;
     printf ( “ enter the three no. “ );
    scanf( “ %d %d %d “ , &a , &b , &c ) ;
   findsmallest ( a , b , c );
  getch () ;
  }

P5. Program to create a function as named “ chckpalindrome() “. And to input no. as parameter after that check no. is palindrome or not.


#include<stdio.h>
#inclued<conio.h>
 void input();
 void checkpalindrome();
 void main()
  {
   clrscr();
   int a ;
   input();
   checkpalindrome();
  getch();
  }
void input()
  {
   printf( “ Enter the number  ” );
   scanf( “  %d “, &a  );
  }
 void checkpalindrome ( int a )
   {
   int rev = 0 , d ;
  num = a;
   while ( a > 0 )
    {
     d = a % 10 ;
   rev = rev * 10 + d ;
    a = a / 10 ;
    }
   if ( num == rev )
    printf ( “ Palindrome “ ) ;
   else
   printf ( “ Not palindrome “ ) ;
   }

P6. Program to input two number as parameter after that check both numbers are amicable by implementing function .

#include<stdio.h>
#inclued<conio.h>
  void input();
  void checkamicable( int , int );
  void main()
  {
   clrscr();
   int a , b ;
   input();
   checkamicable( a , b ) ;
  getch();
  }
 void input()
  {
   printf( “ Enter the two number  ” );
   scanf( “  %d  %d  “, &a, &b  );
  }
 void checkamicable ( int a , int b )
   {
    int   i , s1 = 0 , s2 = 0 ;
    for ( i = 1 ; i < a ; i ++ )
  {
    if ( a % i == 0 )
     s1 = s1 + i ;
   }
    for ( i = 1 ; i < b ; i ++ )
   {
      if ( b % i == 0 )
        s2 +=  i ;
    }
   if ( s1 == b && s2 == a )
   printf ( “ Amicable no . “ ) ;
  else
   printf ( “ Not amicable no. “ );
  }

P10. Program to input any binary number after that convert into decimal using return type parametrical function .

#include<stdio.h>
#include<conio.h>
  int binarytodecimal( int n )
  {
    int d , i = 1 , sum = 0 ;
   while ( n > 0 )
   {
     d = n % 10 ;
    sum = sum + d * i ;
    i = i * 2 ;
    n = n / 10 ;
     }
     return ( sum );
  }
   void main ()
  {
    clrscr();
    int n ;
    printf ( “ Enter any binary number “ ) ;
    scanf ( “ %d “ , &n ) ;
    printf ( “ Decimal no. = %d “ , binarytodecimal ( n ) ) ;
   getch () ;
  }

Monday, October 14, 2019

Function


Key points:


  • It is most important tool in a procedural programming.
  • A function can be defined as a block of statements which is used to perform any particular task according to requirements.
  • The main objective of function is to reduce the complexity of programs.
  • In this case a large program can be divided into multiple parts, that part is called function or module.

There are some advantages of function :-


  • We can create user friendly program with the help of function. In this case the user can create separate function for each module according to requirements.
  • It provides reusability. It means a written source code can be saved multiple times.
  • It provides extendibility . It means a program can be modified and extended in future.
  • It reduces the complexity of programs.
  • It provides readability. It means function oriented program is more readable rather than non function oriented programs.
  • Function creates user friendly program because debugging process is easy.

Types of function :-

There are two types of function :

astepupss c language
Types of function in C
  • Predefined function (inbuilt function)
  • User defined function ( customized function )


Predefind function :-



This type of function is already defined in programming language. We cannot change the behaviour of function.

example:-

  
   printf() , scanf() , clrcr() , getch() , strlen() , etc.

User defined function :-


This type of function is created with the help of user according to requirements.

example:-


findarea() , findfact() , even() , etc.

Function prototype :-


  • It represents architechture of function.
  • It must be required if main function is defined before user defined function.
  • It must be written after declaration of header file.

example:-


#include<stdio.h>
void findsum();
void main()
{
   findsum();
 }
void findsum()
 {
   statements;
  }

How to call a function :-

syntax :-

   
  function name();

example :-


 void main()
  {
    findsum();
   }

Function architecture / pattern :-


It represents type of function as return type , non-return type , parameterised or non-parameterised.

There are four architecture of function :-


  1. A function with no return type and no parameter / argument.
  2. A function with return type but no parameter / arguments.
  3. A function with no return type but with parameter / arguments.
  4. A function with return type and with parameter / arguments.

How to create user defined function :-

1. function with no return type and no parameter

syntax :-


void <function name> ()
 {
    block of stmts;
   }
c language by a step up
function with no return type and no parameter syntax

example :-


 void display()
{
  printf( “ hello” );
 } 

 2. Function with return type but no parameter


syntax:-


   <data type> <function name> ()
{
   block of stmts;
  }
c language by a step up
function with return type but no parameter syntax

example:-


 int findadd()
  {
  int a = 10, b = 20 ;
 add = a + b ;
  return (add) ;
}

 Parameter:- 


Parameter is a special variable which can be supplied during a function and calling a function.

    There are two types of parameter:


        1. formal parameter :- Those parameters which are supplied during creating a function called formal parameter . It is treated as local variable.

        2. actual parameter :- Those parameters which are supplied during  calling a function.  It is also called as argument.

3. A function with no return type but with parameter

  

syntax:-


void <function name> ( <data type> <parameter 1>, ..)
 {
  block of stmts;
  }
c language by a step up
function with no return type but with parameter syntax

 example:-


 void findadd( int a, int b)
{
   int add ;
  add = a + b;
  printf( “ addition = %d “, add);
 }

4. A function witth return type and with parameter


syntax:-


 <data type> < function name > ( parameter list )
 {
   block of stmts;
   return (variable);
 }
c language by a step up
function with return type and with parameter syntax

P.example:- Program to input any no. after that find factorial value using function.


#include<stdio.h>
#include<conio.h>
void findfact()
 {
  int a, fact=1 , i ;
 printf( “ enter the no “ );
 scanf( “ %d “, &a );
  for ( i = 1 ; i <= a ; i ++ )
  {
    if( a % i == 0 )
   fact = fact * i ;
  }
 printf( “ factorial = %d “, fact );
}
void main()
 {
  clrscr ();
 findfact ();
getch ();
 }
We practice more program on this topic on the next blog.


Wednesday, October 9, 2019

Pattern Printing program



Before starting the program ,make sure that you have completed your looping concept of programming . If you not completed yet then visit by clicking here LOOP PROGRAMMING CONCEPT.

 
c language by a step up
A step up programming
You can modify these programming by your own concept.

P1. Program to print the given pattern :-

 
 c language by A step up
P1. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 5 ; j ++ )
   {
    if ( j <= i )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P2. Program to print the given pattern :-

 
c language by a step up
P2. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 5 ; j ++ )
   {
    if ( j >= 6-i )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P3. Program to print the given pattern :-

 
c language by a step up
P3. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 5 ; j ++ )
   {
    if ( j >= i )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P.4 Program to print the given pattern :-

 c language by a step up
P4. Pattern in c

#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 5 ; j ++ )
   {
    if ( j <= 6-i )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P.5 Program to print the given pattern :-

 
c language by a step up
P5. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 9 ; j ++ )
   {
    if ( j >= 6-i && j <= 4+i )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P.6 Program to print the given series :-

 
c language by a step up
P6. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j , k ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    k=1;
    for ( j = 1 ; j <= 9 ; j ++ )
   {
    if ( j >= 6-i && j <= 4+i && k )
      {
       printf ( “ * “ );
        k = 0;  
        }
     else
       {
        printf ( “  “ );
         k = 1 ;
          }
    }
  printf ( “ \n “ );
 }
getch ();
}

P.7 Program to print the given pattern :-

 
c language by a step up
P7. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  for ( i = 1 ; i <= 5 ; i ++ )
  {
    for ( j = 1 ; j <= 9 ; j ++ )
   {
    if ( j <= 6-i || j >= 4 + i)
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P.8 Program to print the given pattern :-

 
c language by a step up
P8. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j , k ;
  for ( i = 1 ; i <= 4 ; i ++ )
  {
     k=1;
    for ( j = 1 ; j <= 7 ; j ++ )
   {
    if ( j >= 5-i && j <= 3+i )
      {
       printf ( “ %d “ , k );
        j<4?k++:k--;
       }
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}

P.9 Program to print the given pattern :-

 
c language by a step up
P9. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j ;
  char k ;
  for ( i = 1 ; i <= 4 ; i ++ )
  {
    k = ‘A’ ;
    for ( j = 1 ; j <= 7 ; j ++ )
   {
    if ( j <= 5-i || j >= 3+i )
     {
       printf ( “ %c “ , k );
        j <4 ? k++ : j-- ;
       }
     else
      {
        printf ( “  “ );
        if ( j == 4 )
            k--;
        }
    }
  printf ( “ \n “ );
 }
getch ();
}

P.10 Program to print the given pattern :-

 
c language by a step up
P10. Pattern in c
#include<stdio.h>
#include<conio.h>
void main()
{
  int i , j , k = 0;
  for ( i = 1 ; i <= 7 ; i ++ )
  {
    i <= 4 ? k++ : k-- ;
    for ( j = 1 ; j <= 7 ; j ++ )
   {
    if ( j >= 5-k && j <= 3+k )
       printf ( “ * “ );
     else
        printf ( “  “ );
    }
  printf ( “ \n “ );
 }
getch ();
}
If You want more pattern program like this then follow my blog and comment below .
share this blog to the needed person.

There are lots of more pattern like this which was updated later, so connect with us.
Basic concept of programming
More uderstanding program