Pavan Ramamurthy
We have an array of integers like shown below int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 }; Write logic to find the repeated integers and their count.
By Pavan Ramamurthy in C# on Aug 21 2013
  • Aman Jain
    Oct, 2013 23

    foreach (int i in arr) {int rpt = arr.Where(val => val == i).ToArray().Length;if(rpt > 1)Console.WriteLine("Number ={0}, Occurrances ={1}",i,rpt);arr = arr.Where(val => val != i).ToArray(); }

    • 2
  • Pavan Ramamurthy
    Aug, 2013 21


     public void Repeated()
            {
                int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };

                for (int i = 0; i             {
                    for (int j=i+1; j                 {
                        if(arr[i]==arr[j])
                        {
                            Console.WriteLine(arr[i]);
                        }
                    }
                }
            }

    • 2
  • Tanuj Khurana
    Aug, 2015 13

    // This is optimized code static void Main(string[] args){int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };for (int i = 0; i < arr.Length;i++){int tpt = 0;if(arr.Contains(arr[i])){tpt = arr.Where(x => x == arr[i]).ToArray().Count();}Console.WriteLine(string.Format("The value is {0} and count is {1}", arr[i], tpt));}Console.ReadLine();}

    • 1
  • varaprasad mullapudi
    May, 2016 12

    int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };var count = arr.GroupBy(item => item).Select(grp => new {Number = grp.Key,numberCount = grp.Count() });

    • 0
  • Shivshanker Cheral
    Nov, 2015 24

    List numbers = new List() { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };var uni = from n in numbersgroup n by n into glet count = g.Count()orderby g.Keyselect new { Value = g.Key, Count = count };foreach (var n in uni)Console.WriteLine("Value: " + n.Value + " Count: " + n.Count);

    • 0
  • Shivshanker Cheral
    Nov, 2015 24

    List numbers = new List() { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };var uni = from n in numbersgroup n by n into glet count = g.Count()orderby g.Keyselect new { Value = g.Key, Count = count };foreach (var n in uni)Console.WriteLine("Value: " + n.Value + " Count: " + n.Count);

    • 0
  • Nacx
    Aug, 2015 3

    var repeatativeValues = arr.GroupBy(t => t).ToList().Where(t => t.Count() > 1).ToList().Select(t => new { Value = t.Key, Count = t.Count() }).ToList();

    • 0
  • Gokul Rathod
    Nov, 2014 25

    int[] Duplicatearr=new int[]{ }; for(int i = 0; i < arr.Length; i ) { if(arr.Containt(arr[i])) {Duplicatearr.Add(a[i]); }}

    • 0
  • kumar Kashyap Pandey
    Dec, 2013 31

    private static void FindRepeatedNumber(){Dictionary duplicateNumbers = new Dictionary();int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 }; for (int i = 0; i 1){Console.WriteLine("Here are list of repeated numbers with their count!");foreach (var item in duplicateNumbers){Console.WriteLine("This number:{0} is occured {1} time(s).", item.Key, item.Value + 1);}}elseConsole.WriteLine("Reapeated number(s) not found in the list!");}}

    • 0
  • Subhranshu Nath
    Nov, 2013 26

    static void Main(string[] args) { int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 }; for (int i = 0; i < arr.Length; i++) { for (int j = i + 1; j

    • 0
  • Abdul Rizwan
    Sep, 2013 10

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program {public static void counter(int[] arr) { int [] arr2=new int[20]; int l = 0;for (int i = 0; i < arr.Length ; i++) {int count=1; foreach (int x in arr2) { if (x == arr[i]) { i++; continue; } } for (int j = i + 1; j < arr.Length; j++) { if (arr[i] == arr[j]) { count++; arr2[l++] = arr[i]; } } Console.WriteLine(arr[i]+" is repeted " + count + " Times"); }} static void Main(string[] args) { int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };counter(arr); Console.ReadKey(); }} }

    • 0
  • Abdul Rizwan
    Sep, 2013 10

    using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication2 {class Program{public static void counter(int[] arr){int [] arr2=new int[20];int l = 0;for (int i = 0; i < arr.Length ; i++){ int count=1;foreach (int x in arr2){if (x == arr[i]){i++;continue;}}for (int j = i + 1; j < arr.Length; j++){if (arr[i] == arr[j]){count++;arr2[l++] = arr[i];}}Console.WriteLine(arr[i]+" is repeted " + count + " Times");}}static void Main(string[] args){int[] arr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };counter(arr);Console.ReadKey();} } }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS