-->

Program to sort 10 numbers using pointer.

using codeblocks
---------------------------------------------------------------------------------------
//program to sort numbers using pointer //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,j,k;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                       //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("before sorting,values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address before sorting
    }
    printf("after sorting,values are\n");
    for(i=0;i<total;i++)
    {
        for(j=i+1;j<total;j++)
        {
            if(*(p+i)>*(p+j))               //sorting swapping taking place with its value
            {
                k=*(p+i);
                *(p+i)=*(p+j);
                *(p+j)=k;
            }
        }
    }
    for(i=0;i<total;i++)              //value display in sorted form
{
    printf("%d\n",*(p+i));
}
    return 0;
}
----------------------------------------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------------------------------------
//program to sort numbers using pointer //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,j,k;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                       //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("before sorting,values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address before sorting
    }
    printf("after sorting,values are\n");
    for(i=0;i<total;i++)
    {
        for(j=i+1;j<total;j++)
        {
            if(*(p+i)>*(p+j))               //sorting swapping taking place with its value
            {
                k=*(p+i);
                *(p+i)=*(p+j);
                *(p+j)=k;
            }
        }
    }
    for(i=0;i<total;i++)              //value display in sorted form
{
    printf("%d\n",*(p+i));
}
getch();    
return 0;
}

Program to sort 10 numbers using pointer.

using codeblocks
-------------------------------------------------------------------
//program to sort numbers using pointer //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,j,k;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("before sorting,values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address before sorting
    }
    printf("after sorting,values are\n");
    for(i=0;i<total;i++)
    {
        for(j=i+1;j<total;j++)
        {
            if(*(a+i)>*(a+j))               //sorting swapping taking place with its value
            {
                k=*(a+i);
                *(a+i)=*(a+j);
                *(a+j)=k;
            }
        }
    }
    for(i=0;i<total;i++)              //value display in sorted form
{
    printf("%d\n",*(a+i));
}
    return 0;
}
------------------------------------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------------------------------
//program to sort numbers using pointer //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,j,k;          //variable declaration
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("before sorting,values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address before sorting
    }
    printf("after sorting,values are\n");
    for(i=0;i<total;i++)
    {
        for(j=i+1;j<total;j++)
        {
            if(*(a+i)>*(a+j))               //sorting swapping taking place with its value
            {
                k=*(a+i);
                *(a+i)=*(a+j);
                *(a+j)=k;
            }
        }
    }
    for(i=0;i<total;i++)              //value display in sorted form
{
    printf("%d\n",*(a+i));
}
   getch();
    return 0;
}

Program to swap two numbers using pointer.

using codeblocks
-------------------------------------------------------------------------------------------
//pointer to swap two numbers
#include <stdio.h>

int main()
{
    int num1,num2,t;                //variables declaration
    int *p1,*p2;                     //pointer to store address
    printf("enter two numbers\n");
    scanf("%d%d",&num1,&num2);      //gets input
    printf("before swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//display of values before swap
    p1=&num1;                             //assignment of address to first pointer
    p2=&num2;                              // assignment of address to second pointer
    t=*p1;                                //assigning first value to third variable
    *p1=*p2;                              //assigning second value to first pointer
    *p2=t;                                 //assigning first  value to second pointer
     printf("after swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//prints values after swapping
    return 0;
}

-------------------------------------------------------------------------------------
using turbo c++
-----------------------------------------------------------------------------------------------------
//pointer to swap two numbers
#include <stdio.h>
#include<conio.h>
int main()
{
    int num1,num2,t;                //variables declaration
    int *p1,*p2;                     //pointer to store address
    printf("enter two numbers\n");
    scanf("%d%d",&num1,&num2);      //gets input
    printf("before swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//display of values before swap
    p1=&num1;                             //assignment of address to first pointer
    p2=&num2;                              // assignment of address to second pointer
    t=*p1;                                //assigning first value to third variable
    *p1=*p2;                              //assigning second value to first pointer
    *p2=t;                                 //assigning first  value to second pointer
     printf("after swapping\n");
    printf("num1=%d,num2=%d\n",num1,num2);//prints values after swapping
   getch();    
return 0;
}

Program to find factorial value of a number using pointer.

using codeblocks
---------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
    return 0;
}

------------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------------------
//program to get factorial value of a number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int i,facto=1;                //variable initialization
    int number;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter a number\n");
    scanf("%d",&number);              //input of a number
    p=&number;                             //storing of address to pointer
    for(i=1;i<=*p;i++)                   //execution of loop till the value reaches to last
    {
        facto=facto*i;                   //continuous multiplication

    }
        printf("factorial value=%d",facto);       //display of output
     getch();
    return 0;
}

Program to input 20 numbers and pick the greatest one using pointer.

using codeblocks
------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file

int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    p=a;                             //storing of base address to pointer
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",p+i);                  //input of element using pointer. here array's base address is used for input
                                          //It gets input using address starting from base location 0.
                                          //It goes on increasing (address) as the loop moves ahead.
    }
    max=*(p+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(p+i))                   //comparison takes place
       {
         max=*(p+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
    return 0;
}
--------------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    int *p;                      //pointer declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    p=a;                             //storing of base address to pointer
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",p+i);                  //input of element using pointer. here array's base address is used for input
                                          //It gets input using address starting from base location 0.
                                          //It goes on increasing (address) as the loop moves ahead.
    }
    max=*(p+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(p+i))                   //comparison takes place
       {
         max=*(p+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
getch();   
return 0;
}


Program to input 20 numbers and pick the greatest one using pointer.

using codeblocks
------------------------------------------------------------------------------------------------

//Program to input 20 numbers and pick the greatest one using pointer.
#include <stdio.h>            //header file
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",a+i);                  //input of element using array. here array acts as pointer.
                                          //It gets input using address starting from location 0.
    }
    max=*(a+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(a+i))                   //comparison takes place
       {
         max=*(a+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
    return 0;
}
-------------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------------
//program to pick the greatest number using pointer
#include <stdio.h>            //header file
#include<conio.h>
int main()
{
    int a[100];                 //array declaration
    int i,max;
    int total;                   //variables declaration
    printf("enter value of total\n");
    scanf("%d",&total);              //input of total value of array
    printf("enter elements of array\n");
    for(i=0;i<total;i++)                   //execution of loop
    {
        printf("enter value for location=%d\t",i);
        scanf("%d",a+i);                  //input of element using array. here array acts as pointer.
                                          //It gets input using address starting from location 0.
    }
    max=*(a+0);                          //It stores value stored in location 0
    for(i=0;i<total;i++)
    {
       if(max<*(a+i))                   //comparison takes place
       {
         max=*(a+i);                    //assigning value
       }
    }
    printf("max value=%d",max);       //display of maximum value
getch();   
 return 0;
}


program to input elements of array and display them using pointer.

using codeblocks
-------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    return 0;
}

---------------------------------------------------------------------------------------------------
or
-------------------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file

int main()                   //main function
{
 
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
   //p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",a+i);   //gets value for given address. This input goes upto last value of address
                                     //array itself is a pointer. It accepts value for first location and so on.
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(a+i));//displays its value with the help of address
    }
    return 0;
}



------------------------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------------
//program to input elements for an array and display using pointer //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i;
    int total;
    printf("enter total number\n");
    scanf("%d",&total);            // gets total value of array.
    p=a;                        //stores base address
    for(i=0;i<total;i++)      //runs from 0 to one less than total
    {
        scanf("%d",p+i);   //gets value for given address. This input goes upto last value of address
    }
    printf("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
getch();
    return 0;
}