Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to print, read and calculate sum, smallest, largest element an array using pointers

Posted By: Easy Tutor     Category: C++ Programming     Views: 7682

A C++ Program to print, read and calculate sum, smallest, largest element an array using pointers.

Code for Program to print, read and calculate sum, smallest, largest element an array using pointers in C++ Programming

 #include<iostream.h>
 #include<conio.h>
 #include<stdio.h>


 void read_array(int *,int );
 void print_array(int *,int );
 int sum_of_array(int *,int);
 int largest(int *,int);
 int smallest(int *,int);


 main( )
    {
       clrscr();

       constint array_size=5;

       int array[array_size]={0};

       cout<<"\n Enter the contents of the array : \n"<<endl;
       read_array(array,array_size);

       clrscr();

       cout<<"\n ********************************************* \n"<<endl;
       cout<<" The contents of the array are :\n"<<endl;
       print_array(array,array_size);
       cout<<"\n *********************************************\n"<<endl;

       getch();

       cout<<"The Sum of the given array is = "<<sum_of_array(array,array_size)<<endl;
       cout<<"\n *********************************************\n"<<endl;

       getch();

       cout<<"The maximum element of the array is = "<<largest(array,array_size)<<endl;
       cout<<"\n ********************************************* \n"<<endl;

       getch();

       cout<<"The minimum element of the array is = "<<smallest(array,array_size)<<endl;
       cout<<"\n ********************************************** "<<endl;

       getch();
       return 0;
    }

 /*************************************************************************//*************************************************************************///------------------------  Function Definitions  -----------------------///*************************************************************************//*************************************************************************//*************************************************************************///-----------------------  read_array(int *,int)  -----------------------///*************************************************************************/void read_array(int *array,int array_size)
    {
       for(int count=0;count<array_size;count++)
      {
         cin>>*array;
         array++;
      }
    }

 /*************************************************************************///-----------------------  print_array(int *, int)  ---------------------///*************************************************************************/void print_array(int *array,int array_size)
    {
       for(int count=0;count<array_size;count++)
      {
         cout<<"\t\t\t Element ["<<count<<"] = "<<*array<<endl;
         array++;
      }
    }

 /*************************************************************************///----------------------  sum_of_array(int *,int)  ----------------------///*************************************************************************/int sum_of_array(int *array,int array_size)
    {
       int count;
       int sum=0;

       for(count=0;count<array_size;count++)
      {
         sum=sum+*array;
         array++;
      }

       return sum;
    }

 /*************************************************************************///-------------------------  largest(int *,int)  ------------------------///*************************************************************************/int largest(int *array,int array_size)
    {
       int max=*array;

       for(int count=0;count<array_size;count++)
      {
         if(*array>max)
        max=*array;

         array++;
      }

       return max;
    }

 /*************************************************************************///-------------------------  smallest(int *,int)  -----------------------///*************************************************************************/int smallest(int *array,int array_size)
    {
       int min=*array;

       for(int count=0;count<array_size;count++)
      {
         if(*array<min)
        min=*array;

         array++;
      }

       return min;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to print, read and calculate sum, smallest, largest element an array using pointers is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Arun Kumarreddy from India Comment on: Oct 09
Write a program to read an integer in the range 1 to 9999 as command-line argument, convert and print the value in words. You should do validity check on the input. (For example: If the user inputs 504 the output should be “Five hundred
and four)

View All Comments