-->

program to count total number of words,space,consonants in a string using pointer

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

//program to reverse a string using pointer//comment of program
#include <stdio.h>                         //header file
#include<ctype.h>
int main()                              //main function
{
    char name[40];                     //character declaration
    char *p;                          //pointer declaration.
    int length,vowel=0,conso=0,space=0,words=1;
    puts("enter string\n");           //display of message
    gets(name);                      // gets data/string
    length=strlen(name);             //stores length of string
    p=name+length;        // assigning total address as in given string; it becomes total taken from variable length starting from 0.
                      //p=name takes address location 0 to pointer.
    while(p>=name)                 //the value of 'p' decreases from location 15 until it reaches 0.
    {
        if(*p==' ')                 //prints the value stored in particular location
        {
            space++;
        }

        else if(tolower(*p)=='a' ||tolower(*p)=='e' || tolower(*p)=='i' || tolower(*p)=='o' || tolower(*p)=='u')
        {
            vowel++;
        }
        else if(tolower(*p)!='a' ||tolower(*p)!='e' || tolower(*p)!='i' ||
                tolower(*p)!='o' || tolower(*p)!='u' ||
                *p!=' ' || *p!='.')
        {
            conso++;
        }
        p--;
    }
    printf("total vowel=%d,total consonants=%d,total spaces=%d,total words=%d",vowel,conso,space,space+1);
    return 0;
}

----------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h>                         //header file
#include<ctype.h>
#include<conio.h>
int main()                              //main function
{
    char name[40];                     //character declaration
    char *p;                          //pointer declaration.
    int length,vowel=0,conso=0,space=0,words=1;
    puts("enter string\n");           //display of message
    gets(name);                      // gets data/string
    length=strlen(name);             //stores length of string
    p=name+length;        // assigning total address as in given string; it becomes total taken from variable length starting from 0.
                      //p=name takes address location 0 to pointer.
    while(p>=name)                 //the value of 'p' decreases from location 15 until it reaches 0.
    {
        if(*p==' ')                 //prints the value stored in particular location
        {
            space++;
        }

        else if(tolower(*p)=='a' ||tolower(*p)=='e' || tolower(*p)=='i' || tolower(*p)=='o' || tolower(*p)=='u')
        {
            vowel++;
        }
        else if(tolower(*p)!='a' ||tolower(*p)!='e' || tolower(*p)!='i' ||
                tolower(*p)!='o' || tolower(*p)!='u' ||
                *p!=' ' || *p!='.')
        {
            conso++;
        }
        p--;
    }
    printf("total vowel=%d,total consonants=%d,total spaces=%d,total words=%d",vowel,conso,space,space+1);
getch();    
return 0;
}

program to understand pointer's pointer

using codeblocks
----------------------------------------------------------------------------------
//understanding pointer's pointer
#include <stdio.h>

int main()
{
    int **p,*p1;                  //two pointer declaration
    int x=5;
    p1=&x;                        //stores address of x to pointer p1
    printf("first address p1=%d\n",p);//prints that first address
    p=&p1;                         //stores address of pointer by pointer
    printf("address p=%d\n",p);//prints that pointer's address
    return 0;
}
--------------------------------------------------------------------------------

using turboc++
----------------------------------------------------------------------------

//understanding pointer's pointer
#include <stdio.h>
#include <conio.h>

int main()
{
    int **p,*p1;                  //two pointer declaration
    int x=5;
    p1=&x;                        //stores address of x to pointer p1
    printf("first address p1=%d\n",p);//prints that first address
    p=&p1;                         //stores address of pointer by pointer
    printf("address p=%d\n",p);//prints that pointer's address
   getch();
    return 0;
}


Program to find sum and average of 10 numbers using pointer.

using codeblocks
--------------------------------------------------------------------
//program to print sum and average of 10 numbers using pointer. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,k,sum=0;          //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
        sum=sum+*(p+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
    return 0;
}

--------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------------------
//program to print sum and average of 10 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,k,sum=0;          //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
        sum=sum+*(p+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
   getch();
    return 0;
}

---------------------------------------------------------------------------------------------------------
or
----------------------------------------------------
//program to print sum and average of 10 numbers using pointer. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int a[20],i,sum=0;          //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 , starting from 0. This input goes upto last value of address
        sum=sum+*(a+i);   // finds sum
    }
    printf("the sum=%d\n",sum);          // prints sum
    printf("the average =%f\n",(float)sum/total);//prints average
    return 0;
}


program to search location of a number in a list

using codeblocks
---------------------------------------------------------------
//program to print all locations of a number  array. //comment of program
#include <stdio.h>            //header file
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,k,num;          //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("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    printf("enter a number to be searched\n");
    scanf("%d",&num);                    //gets a number to be searched
    for(i=0;i<total;i++)
    {
            if(*(p+i)==num)               //comparison being done  with its value
            {
                 printf("num=%d and its location=%d\n",num,i);//prints value
            }
    }
    return 0;
}

------------------------------------------------------------------------------------------
using turboc++
----------------------------------------------------------------------
//program to print all locations of a number  array. //comment of program
#include <stdio.h>            //header file
#include<conio.h>
int main()                   //main function
{
    int *p;                   //pointer declaration
    int a[20],i,k,num;          //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("values are\n");
    for(i=0;i<total;i++)
    {
        printf("%d\n",*(p+i));//displays its value with the help of address
    }
    printf("enter a number to be searched\n");
    scanf("%d",&num);                    //gets a number to be searched
    for(i=0;i<total;i++)
    {
            if(*(p+i)==num)               //comparison being done  with its value
            {
                 printf("num=%d and its location=%d\n",num,i);//prints value
            }
    }
   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.
    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;
}