Important points about C Language Function

We know that Function is very Important part of C Language. With the help of Function Programs are easy to write and understand. So there are some Key points to remember when deal with C Language Function:  A Function gets called when the Function name is followed by a semicolon(;). Example: int main() { india(); … Continue reading “Important points about C Language Function”

Key Points

We know that Function is very Important part of C Language. With the help of Function Programs are easy to write and understand. So there are some Key points to remember when deal with C Language Function: 

  • A Function gets called when the Function name is followed by a semicolon(;).

Example:

int main()
{
india();                 /* Function calling */
}

  •  A Function can call itself. Such a process is called “recursion”. Discuss later.

    • A Function can be called from another Function, but a Function cannot be defined in another Function.
    Example:
    int main()
    {
    printf(” Hello”);
    void india()                                /* Function definition */
    {
    printf(” I am in India”);
    }

    The above Program code would be wrong because india() is being defined inside another Function main().


    • A Function can be called any number of times.
    Example:
    #include<stdio.h>
    void india();                          /* Function Declaration */
    int main()
    {
    india();                                 /* Function Calling */
    india();                                 /* Function Calling */
    return(0);
    }
    void india()                           /* Function Definition */
    {
    printf(” Hello\n”);
    }

    • The order in which the Functions are defined in a Program and the order in which they get called need not necessarily be same.
    Example:
    #include<stdio.h>
    void India();                                      /* Function Declaration */
    void England();                                  /* Function Declaration */
    int main()
    {
    India();                                             /* Function Calling */
    England();                                         /* Function Calling */
    return(0);
    }
    void England()                                   /* Function Definition */
    {
    printf(” Olympic games”);   
    }
    void India()                                        /* Function Definition */
    {
    printf(” Beautiful city of corruption”);
    }
    India() is getting called before England(), still India() has been defined after England().

    • Any Function can be called from any other Function.
    Example:
    #include<stdio.h>
    void India();                         /* Function Declaration */
    int main()
    {
    India();                                /* Function Calling */
    return(0);
    }
    void India()                          /* Function Definition */
    {
    printf(” Nasa Mars mission successufull”);
    main();                               
    }

    • A Function is defined when Function name is followed by a pair of braces in which one or more statements may be present.
    Example:
    void India()                      /* Function Definition */
    {
    stmt 1;
    stmt 2;
    }
                                                                     That's All 

    How to Crack a Job interview Successfully [Top 15 Tips and Tricks]

    Job Interview
    To have a successful interveiw and to make a lasting impression, the Body Language is very important. Postures and body movements are unconsious forms of expression and therefore they have a language of their own. We are unaware of our gestures and body movements most of the time, but other people can notice our gestures and movements if they pay attention and know what they mean.
                                                            An important thing to be noted here is that body language applies not only to the Interviewer but also to the Interviewee. Also, note that these gestures may happen throughout the conversion or a discussion and they change as the conversation progresses.

    Interview Skills
    The objective of paying attention to nonverbal communication is to help you change the direction of the conversation. If the person is showing negative gestures; then you need to change the topic by asking a new questions or talking about something else.
    Here is a comprehensive list of probable body gestures, which you watch out for during the course of a Job interview :
    • Crossed arms means that person is in a defensive and reserved mood.
    • Crossed arms and legs means that the person is feeling very reserved and suspicious.
    • Open arms and hands means that the persion is open and receptive.
    • Standing before you with hands inside the pockets means he is not sure or fells suspicious.
    • Standing before you with hands on hips means he is receptive and ready to help you out.
    • Rubbing the back of head or touching the back of neck means the conversation is not really interesting.
    • Leaning back in chair with both hands clasped behind head means he is in an analytical mood, but it is also a gesture of superiority.
    • With the palm holding or supporting chin, he is in an evaluating position and being critical.
    • Sitting in a chair shaking one of the legs means he feels nervous and uncomfortable.
    • Rubbing or touching nose when asking a question means he is not telling the complete truth.
    • If the eyes are downcast and face turned away, it means he is not interested in what you are saying.
    • If he moves his body and sits with his feet and body pointing towards a door means he wants to end the conversation and leave the room.
    • If you are nervous try not to show it.
    • Don't play with your watch, clothes, bag etc. Try to maintain eye contact with the interviewer. 
    • Last but not the least, donot underestimate the importance of your posture and subtle movements.

    At Present, we have seen in the Newspapers, Internet and Heard in the TV that in almost all fields of Work , there is a tough competition between the Students , Employees , Workers etc. Everyone tries to become Successfull in the field where they work but during Interviews , if you pay Little attention towards these above small things than probably you might have a Successfull Interview.

                                                                      
                                                                     All the best!

    WAP to determine whether the Number is Prime or Not by using while and if Statement

    C break Statement

    Break Statement:

    There are many situations where we want to jump out of a loop instantly. The keyword break allows us to do this. When break is encountered inside any loop, control automatically passes to the first statement after the loop. So Let us understand the break statement with the help of Program :-
    Statement of C Program: This Program accepts a number and determined whether the number is Prime or not.
    Prime Number:
    A Prime number is one, which is divisible by 1 or itself.  Ex: 3 , 5 , 7 , 11 , 13 , 17 , 23 , 19 etc.
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a , b ;
    clrscr();
    printf(” Enter the value of a\n”);
    scanf(“%d” , &a);
    b = 2;
    while( b <= a-1 )
    {
    if(a % b == 0)
    {
    printf(” Entered Number is not Prime\n”);
    break;
    }
    b = b + 1;                                                   /*   b++     or    b += 1   */
    }
    if(b = a)
    {
    printf(” Prime Number\n”);
    }
    getch();
    }
    Output1:
    Enter the value of a
    7
    Prime Number
    Output2:
    Enter the value of a
    9
    Entered Number is not Prime

    Explanation:

    • In the above Program, if the condition { i.e a % b } turns out to be zero, then the message “ Entered number is not Prime ” is printed and after that the break statement encountered which causes control out of while loop.
    • If the condition { i.e b == a } is true, then the message ” Prime Number ” is printed.
                                                                          
                                                                        That's All

    WAP of C Language that calls many Functions

    C Function Program

    Statement of C Program : This Program prints the Messages or Instructions when different Functions calls: 

    #include<stdio.h>

    void England();                                      /* Function declaration */
    void Australia();                                     /* Function declaration */
    void India();                                           /* Function declaration */
    int main()
    {
    printf(” I am in main\n”);
    England();                                                 /*  Function call */
    Australia();                                                /*  Function call */
    India();                                                      /* Function call */
    return(0);
    }
    void England()                                             /* Function definition */
    {
    printf(” I am in England\n”);
    }
    void Australia()                                             /* Function definition */
    {
    prinf(” I am in Australia\n”);
    }
    void India()                                                   /* Function definition */
    {
    printf(” I am in India\n”);
    }
    Output:
    I am in main
    I am in England
    I am in Australia
    I am in India
    Note:  Number of Conclusions drawn from the above Program:
    • A C Program is a collection of one or more Function or you can say A Function is a basic building block of C program.
    • If a C program contain only one Function, then it must be main(), because Program execution always begins with main().
    • In C program, as many number of Functions exist i.e there is no limit on the number of Functions.
    • Control returns to main() after each Function has doing its work or thing.
    • The Program ends, when main() runs out of statements and Function calls.

                                                                   

                                                                     That's All

    Write a Simple C Function Program that prints the Messages i.e Good Morning? & Good Evening!

    Messages

    Statement of C Program: This Program prints the Messages i.e Good Morning? & Good Evening! with the help of Function :

    This is the Simplest C Function Program. Functions are the basic building blocks of C Program.

    #include<stdio.h>

    void msg();                                            /* Function Declaration */

    int main()

    {
    msg();                                                         /* Function Call */
    printf(” Good Morning?”);
    return(0);
    }
    void msg()                                               /* Function Definition */
    {
    printf(” Good Evening!”);
    }
     Output:
     Good Evening!
     Good Morning?
    Explanation:
    Above, we have defined two Functions- main() and msg(). We have used the word msg at three places in the Program. So Let us understood the meaning of each.
    1. 
    void msg();
    This Function declaration indicates that msg() is a Function which after completing its execution does not return anything. The keyword void is used before the msg() to indicate that it 'does not return anything'.
    2.
    void msg()
    {
    printf(” Good Evening”);
    }
    This is Function definition. In this definition we are using only printf(), but we can also use for , switch , if , while etc inside Function definition.
    3. 
    msg();
    The Function msg() is being called by main() i.e main() calls the function msg(). We mean that control passes to the function msg().
                                                                           That's All

    WAP to Find the Largest Number among Two Numbers by using Function

    Largest Number

    Statement of C Program: This Program prints the Largest Number among two Numbers by using Function.

    #include<stdio.h>

    #include<conio.h>
    void main()
    {
    float a , b , max;
    clrscr();

    float large(float x , float y);                              /* Function declaration */

    printf(” Enter the value of two numbers\n”);
    scanf(“%f%f” , &a , &b);
    printf(“a = %f and b = %f\n” , a, b);
    max = large(a,b);
    printf(” The largest number is = %f\n” , max);
    }                                                                   /* End of main() */
       /* Function to determine the largest number */
    float large(float x , float y)
    {
    if(x>y)
    {
    return(x);
    }
    else                                                               /* ( y>x )  */
    {
    return(y);
    }
    }
    Output:
     12.5
     10.5
     a = 12.5 and b = 10.5
     The largest number is = 12.5
                                                                         That's All

    WAP to Compute the Sum of two Number by using Function

    Sum

    Statement of C Progream: This Program accepts two Integers and Computes their Sum via addnums() :
    There are two methods to write this Program

    1. NON ANSI style
    2. ANSI style

    1. NON ANSI style:

    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    int a , b , result;
    clrscr();
    printf(” Enter the value of two numbers\n”);
    scanf(“%d%d” , &a , &b);
    result = addnums(a , b);
    printf(” sum of %d and %d = %d\n” , a , b , result);
    }                                                      /* End of main */
    /* Function to add two numbers */
    int addnums( var1 , var2)
    int var1 , var2;
    {
    int sum;
    sum = var1 + var2;
    return(sum);
    }                                               /* End of Function */
    Output:
    Enter the value of two numbers
    24
    68
    sum of 24 and 68 = 92
    2. ANSI style:

    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    int a , b , result;
    clrscr();
    printf(” Enter the value of two numbers\n”);
    scanf(“%d%d” , &a , &b);
    result = addnums(a , b);
    printf(” sum of %d and %d = %d\n” , a , b , result);
    }                                                      /* End of main */
    /* Function to add two numbers */
    int addnums( int var1 , int var2)
    {
    int sum;
    sum = var1 + var2;
    return(sum);
    }                                               /* End of Function */

    Output:
    Enter the value of two numbers
    14
    18
    sum of 14 and 18 = 32

                                                                     That's All
                                                                       

    Detailed overview of C Language Function [Tutorial]

    Function

    Functions:
    Function is a set of instructions to carry out a particular task. The Function after processing returns a single value.
    In other word, we say a Function is a group of statements that can perform any particular task. 

    Types of functions:

    Types of Functions

    There are two types of Functions in C

    1. Standard Functions  (Pre-defined Functions)
    2. User-defined Functions

     1. Standard functions:

    All standard functions, such as sqrt() , pow() , log() , sin() etc. are porvided in the library of the functions. The standard functions are also called library functions or built in functions. Predefined Functions are already created. Eg: printf() , scanf() , getch() , clrscr() etc.
    2. User defined functions:
    User defined Functions which are created by the User according to his need.
    Function Defination:
    Defining a function means writing an actual code for a function. Suppose you are defining a function which computes the square of a given number. Then you have to write a set of instructions to do this. There are different methods to define functions. The following two ways are used in defining functions:
    1. NON ANSI style
    2. ANSI style
    1. NON ANSI style
    The general form of NON ANSI function definition is as follows:
    type name_of_the_function (parameter list)
    parameter definition;
    {
    variable declaration;
    stmt 1; 
    stmt2;
    …….
    …….
    return(value_computed);
    }
    where
    • type => The data type of the return value by the function. 
    • name_of_the_function => This is a user-defined function name.
    • parameter list => List of variables that recieve, the value from the calling function. 
    • parameter definition => Type declaration of the variables of the parameter list.
    • return => A keyword used to send the output of the function, back to the calling function. There may be one or more return statements. When return is e

    WAP to Find the Average Male Height and Female Height in the Class

    Average Height

    Statement of C Program: This Program Prints the Average Height of Male and Female :

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int mh[3] , fh[3] , i ;           /* mh stands for Male Height and fh stands for Female Height */
    float mtot , ftot ;          /* mtot stands for Male total height and ftot stands for Female total Height */
    float mavg , favg ;       /* mavg stands for Males Average Height and favg stands for Females Average Height */
    clrscr();
    mavg = 0;
    favg = 0;
    for(i=0 ; i<3 ; i++)
    {
    printf(” Enter height of male %d :” , i+1);
    scanf(“%d” , &mh[i] );
    mtot = mh[i] + mtot;
    }
    mavg = mtot/3;
    printf(“\n”);
    for(i=0 ; i<3 ; i++)
    {
    printf(” Enter height of female %d :” , i+1);
    scanf(“%d” , &fh[i] );
    ftot = ftot + fh[i];
    }
    favg = ftot/3;
    printf(“\n”);
    printf(” Average of male height = %f\n” , mavg);
    printf(” Average of female height = %f\n” , favg);
    getch();
    }                                                 /* End of main() */
     Output:
     Enter height of male 1 : 150
     Enter height of male 2 : 170
     Enter height of male 3 : 190
     Enter  height of female 1 : 160
     Enter  height of female 2 : 180
     Enter  height of female 3 : 200
     Average of male height = 170
     Average of female height = 180 


                                                                      
                                                                    That's All

    WAP to Find the Largest and Second Largest Number out of 10 Array Elements

    Largest and Second Largest Number

    Statement of C Program: This Program Prints the Largest and Second Largest Number out of 10 Array Elements:

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int A[10];
    int i , j , b;
    clrscr();

    for(i=0 ; i<10 ; i++)
    {
    printf(” Enter the Number %d :” , i+1 );
    scanf(“%d” , &A[i] );
    }

    for(i=0 ; i<10 ; i++)
    {
    for(j=i ; j<10 ; j++)
    {
    if(A[i] < A[j])
    {
    b = A[j] ;
    A[j] = A[i] ;
    A[i] = b ;
    }
    }
    }

    printf(” Largest Number is : %d\n” , A[0] );
    printf(” Second Largest Number is : %d\n” , A[1] );
    getch();
    }                                                     /* End of main() */

    Output:
    Enter the Number 1 : 90
    Enter the Number 2 : 80
    Enter the Number 3 : 70
    Enter the Number 4 : 60
    Enter the Number 5 : 50
    Enter the Number 6 : 40
    Enter the Number 7 : 30
    Enter the Number 8 : 20
    Enter the Number 9 : 10
    Enter the Number 10 : 110
    Largest Number is : 110
    Second Largest Number is : 90

                                                                         That's All