1,105,363 Community Members

How to calculate the sum & product of dis-similar numbers of an array[10].

Member Avatar
fashxfreak
Light Poster
30 posts since Jul 2011
Reputation Points: 3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How to calculate the sum & product of dis-similar numbers of an array[10].
i do have a code but it stop working after a certain limit, so please help.....

Member Avatar
Momerath
Senior Poster
3,822 posts since Aug 2010
Reputation Points: 1,323 [?]
Q&As Helped to Solve: 661 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

Let's see what you have

Member Avatar
fashxfreak
Light Poster
30 posts since Jul 2011
Reputation Points: 3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Let's see what you have

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, k, sum, c;
            

            sum = 0;
            int[] m = new int[10];
            for (k = 0; k < 10; k++)
            {
                Console.Write("Enter Value: ");
                m[k] = Convert.ToInt16(Console.ReadLine());
            }

            for (i = 0; i < 10; i++)
            {

                c = 0;

                for (j = i + 1; j < 10; j++)
                {

                    if (m[i] == m[j] && c==0)
                    {
                        sum = sum + m[i];
                        sum = sum + m[j];
                        m[j] = 0;

                        c++;

                    }
                    else if (m[i] == m[j])
                    {
                        
                        sum = sum + m[j];
                        m[j] = 0;



                    }



                }



            }
            Console.WriteLine("sum of similar numbers : " + sum);

            Console.ReadLine();
        }
    }
}

// sum of dissimilar numbers can simply be found by subtracting the sum of similar numbers from the total sum.....

Member Avatar
fashxfreak
Light Poster
30 posts since Jul 2011
Reputation Points: 3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int i, j, k, p;


            p = 1;
            int[] m = new int[4];
            for (k = 0; k < 4; k++)
            {
                Console.Write("Enter Value: ");
                m[k] = Convert.ToInt16(Console.ReadLine());
            }

            for (i = 0; i < 4; i++)
            {


                for (j = i + 1; j < 4; j++)
                {
                    if (m[i] == m[j])
                    {
                        m[j] = 1;
                        if (j == 3)
                        {
                            m[i] = 1;
                        }
                    }


                }








            }
            for (k = 0; k < 4; k++)
            {
                p = p * m[k];
            }
            if (p == 1)
            {
                Console.WriteLine("Product of dis-similar numbers :  0");

            }
            else
            {
                Console.WriteLine("sum of similar numbers : " + p);
            }
            Console.ReadLine();
        }
    }
}

Let's see what you have

Member Avatar
Aslan89
Newbie Poster
1 post since Dec 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 3, 5, 7, 1, 3, 8, 7, 1, 1, 10, 15, 32, 3 };

            int sum = 0;
            int mul = 1;
            int count = 0;

            for (int k = 0; k < arr.Length; k++ )
            {
                for (int i = 0; i < arr.Length; i++)
                    if (arr[k] == arr[i])
                        count++;

                if (count == 1)
                {
                    sum += arr[k];
                    mul *= arr[k];
                }

                count = 0;
            }

            Console.WriteLine("Sum = : {0}\nMul = : {1}", sum, mul);
            Console.ReadKey();
        }
    }
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: