Comments

Tuesday, August 27, 2013

Find all numbers in an array whose sum is equal to 25

Posted by at 1:51 AM Read our previous post


Object:

1. Find all numbers in an array whose sum is equal to 25

Source Code;

#include <iostream>
using namespace std;

class arry
{
private:
      
public:
       int sum,i,j,box[2],f,s;
       int *ary(int ary[10])
       {
             
              for(i=0;i<10;i++)
              {
                     for(j=i+1;j<10;j++)
                     {
                           f=ary[i];
                           s=ary[j];
                           sum=f+s;

                           if (sum==25)
                           {

                           cout<<f<<" : "<<s;
                          
                          
                           }box[0]=f;
                           box[1]=s;
                           return box;
                          
                          
                     }
              }
      
       }

};
 void main()
 {
        arry ary;

        int *ptr,count=0;

        int ay[10];
       cout<<"Enter digits in array"<<endl;

       for(int i =0; i<10;i++)
              {
                     cin>>ay[i];
              }
      
       ary.ary(ay);

       ptr=ary.ary(ay);

       for(count;count<2;count++)
       {
              cout<<"Return value are : "<<ptr[count]<<endl;
      
      
       }


       system("pause");
 }









Output:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template