-->

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


No comments:

Post a Comment