-->

External storage (also called global storage or variables:

in turboc++
-------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
    printf("value of a and b from main function are=%d and %f\n",a,b);
    function();//function calling
    return 0;
}
void function()//function body line
{

        printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}

















---------------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to understand global variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
extern int a=5;// or simply int a //global variable; can be used with keyword extern
float b=4.5;//global variable;can be used with extern keyword
void function();
int main()
{
    printf("value of a and b from main function are=%d and %f\n",a,b);
    function();//function calling
    getch();
    return 0;
}
void function()//function body line
{

        printf("from user defined function a=%d,b=%f\n",a,b);//printing value
}

Automatic (also called local variables):

in turbo c++
-----------------------------------------------------------------------------
//program to understand local variable .
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void function();
int main()
{
    function();//function calling
   getch();
    return 0;
}
void function()//function body line
{

    auto int a=4;//local variable, it can not be accessed from outsides. we can also use keyword auto.
    float b=7.89;//local variable// can not be accessed from outsides
    printf("a=%d,b=%f",a,b);//printing value
}







---------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------
//program to understand local variable .
#include <stdio.h>
#include <stdlib.h>
void function();
int main()
{
    function();//function calling
    return 0;
}
void function()//function body line
{

    auto int a=4;//local variable, it can not be accessed from outsides. we can also use keyword auto.
    float b=7.89;//local variable// can not be accessed from outsides
    printf("a=%d,b=%f",a,b);//printing value
}

WAp to concatenate two strings. Use no arguments and return its output.

in turboc++
-----------------------------------------------------------------------------------------------------------

//WAP to concatenate two  strings using(strcat()) function.Pass no parameters and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat();//prototype of function(must as pointer)
int main()
{
    printf("merged string=%s\n",stringcat());//prints with calling
     getch();
    return 0;
}
char *stringcat()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input

   
    return strcat(name,name1);//returning the concatenated string
}









----------------------------------------------------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------------------------------------------
//WAP to concatenate two  strings using(strcat()) function.Pass no parameters and return its result
#include <stdio.h>
#include<string.h>
#include<conio.h>
char *stringcat();//prototype of function(must as pointer)
int main()
{
    printf("merged string=%s\n",stringcat());//prints with calling
     getch();
    return 0;
}
char *stringcat()
{
    char name[100],name1[100];// declaration
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//can be used
    gets(name); //first string input
    printf("enter second string\n");
    gets(name1);//second string input

   
    return strcat(name,name1);//returning the concatenated string
}

WAP to get square root of a number using function.

in turboc++
----------------------------------------------------------------------------------------

//program to get  square root of a number using function.Use no argument and return some value
#include <stdio.h>  //header file
#include<math.h>
#include<conio.h>
 float square_root();//function prototype
int main()                 //main function
{
    printf("square root=%f",square_root());          // function calliing with output
    getch();
    return 0;             // returning 0 value
}

float square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
 
        square=sqrt(n);            // finding sum of two numbers
        return square;      //return of square
   
}










-------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------------------
//program to get  square root of a number using function.Use no argument and return some value
#include <stdio.h>  //header file
#include<math.h>
#include<conio.h>
 float square_root();//function prototype
int main()                 //main function
{
    printf("square root=%f",square_root());          // function calliing with output
    getch();
    return 0;             // returning 0 value
}

float square_root()      //function body line/definition
{
    float n,square;       // initilizating value 1
    printf("enter value");// display of those value
    scanf("%f",&n);
 
        square=sqrt(n);            // finding sum of two numbers
        return square;      //return of square
   
}

WAp to know a number is prime or composite or not using function.

turboc++
-------------------------------------------------------------------------------------------------

//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h>                      //header file
#include<conio.h>
int prime_number();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
    int result;
result=prime_number();                                     // function calling.
if(result==0)                        //condition testing
{
    printf("it is prime\n");         //printing output
   
}
else
{
printf("it is not prime\n");
}
getch();
return 0;                                       //returns 0 value
}
int prime_number()                           // function body line ; also called function definition
{
 int i,number,count=0;                    // variable declaration
printf("enter a number\n");               //message display to input a number
scanf("%d",&number);                      //gets input
for(i=2;i<number;i++)                     //executing from 2 to <n
{
    if(number%i==0)                       //testing for next number
    {
        count=1;                        //assigning to  1 to count
 
    }
 

 if(count==0)                                //testing count ;whetehre it has 0 or 1
 {
    return count;                    //returning count
 }
 else
 {
     return;                      //returns nothing
 }
}







--------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h>                      //header file
#include<conio.h>
int prime_number();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
    int result;
result=prime_number();                                     // function calling.
if(result==0)                        //condition testing
{
    printf("it is prime\n");         //printing output
   
}
else
{
printf("it is not prime\n");
}
getch();
return 0;                                       //returns 0 value
}
int prime_number()                           // function body line ; also called function definition
{
 int i,number,count=0;                    // variable declaration
printf("enter a number\n");               //message display to input a number
scanf("%d",&number);                      //gets input
for(i=2;i<number;i++)                     //executing from 2 to <n
{
    if(number%i==0)                       //testing for next number
    {
        count=1;                        //assigning to  1 to count
 
    }
 

 if(count==0)                                //testing count ;whetehre it has 0 or 1
 {
    return count;                    //returning count
 }
 else
 {
     return;                      //returns nothing
 }
}

WAP to get reverse of a number using function.

using turboc++
--------------------------------------------------------------------------------------------
//program to get reverse of a number using function.use no arguments and return some value

#include<stdio.h>                      //header file
#include<conio.h>
int reverse();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
printf("reverse =%d",reverse());            // function callingwith output.
getch();
return 0;                                       //returns 0 value
}
int reverse()                              // function body line ; also called function definition
{
int s=0,rem;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(;n!=0;)                     //loop running from 1 to 100 with increment 1 each time
{
    rem=n%10;               //finding remainder
    s=s*10+rem;
    n=n/10;                 //finding next integer number and trasnforming that into 'n'
}
 
return s;            //returning value       
}






---------------------------------------------------------------------------------------------------------------
using codeblocks:
-------------------------------
//program to get reverse of a number using function.use no arguments and return some value

#include<stdio.h>                      //header file
int reverse();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
printf("reverse =%d",reverse());            // function callingwith output.
return 0;                                       //returns 0 value
}
int reverse()                              // function body line ; also called function definition
{
int s=0,rem;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(;n!=0;)                     //loop running from 1 to 100 with increment 1 each time
{
    rem=n%10;               //finding remainder
    s=s*10+rem;
    n=n/10;                 //finding next integer number and trasnforming that into 'n'
}
 
return s;            //returning value       
}

wap to find factorial value of a number using function.

in turboc++
-----------------------------------------------------------------------------
//program to get factorial value of a number using function.use no arguments and return some value
#include<stdio.h>                      //header file
#include<conio.h>
int factorial();                          // function prototype/declaration with return type int.
int main()                              //main function
{
printf("factorial value=%d",factorial()); // function calling with value.
return 0;                                       //returns 0 value
}
int factorial()                              // function body line ; also called function definition
{
int factorial_value=1,i;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(i=1;i<=n;i++)                     //loop running from 1 to 100 with increment 1 each time
{
    factorial_value=factorial_value*i;                //formulation for factorial
}
return factorial_value;      // returning output of function
}



------------------------------------------------------------------------------------------------------
in codeblocks:
-------------------------------------------------------------------------------------------------------
//program to get factorial value of a number using function.use no arguments and return some value
#include<stdio.h>                      //header file
int factorial();                          // function prototype/declaration with return type int.
int main()                              //main function
{
printf("factorial value=%d",factorial()); // function calling with value.
getch();
return 0;                                       //returns 0 value
}
int factorial()                              // function body line ; also called function definition
{
int factorial_value=1,i;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(i=1;i<=n;i++)                     //loop running from 1 to 100 with increment 1 each time
{
    factorial_value=factorial_value*i;                //formulation for factorial
}
return factorial_value;      // returning output of function
}