-->
Showing posts with label Program to input 20 numbers and pick the greatest one using pointer.. Show all posts
Showing posts with label Program to input 20 numbers and pick the greatest one using pointer.. Show all posts

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;
}