Wednesday, 28 October 2015

C# Program to Count the Number of 1's in the Entered Number??

class Program
    {
        static void Main(string[] args)
        {
            int x, count = 0;
            Console.WriteLine("Enter the Limit : ");
            x = int.Parse(Console.ReadLine());
            int[] a = new int[m];
            Console.WriteLine("Enter the Numbers :");
            for (int i = 0; i < m; i++)
            {
                a[i] = Convert.ToInt32(Console.ReadLine());
            }
            foreach (int o in a)
            {
                if (o == 1)
                {
                    count++;
                }
            }
            Console.WriteLine("Number of 1's in the Entered Number : ");
            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
---------------------
OUTPUT
Enter the Limit : 6
Enter the Numbers :
1
2
1
4
1
2
Number of 1's in the Entered Number : 3
--------------------

No comments:

Post a Comment