Algorithm:-
(1)Start
(2)Take variable count with initial value zero
(3)take number from user and store in variable L
(4)make a array of integer with limit L
(5)insert the values in array one by one from 1 to L
(6)compart the every of array with one and increment the count values when condition is true
(7)print the final value of count with message number of one’s in the entered number is count
(8)Stop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApplicationOnly
{
class Program
{
static void Main(string[] args)
{
try
{
int L, count = 0;
Console.WriteLine("Enter the Limit : ");
L= int.Parse(Console.ReadLine());
int[] a = new int[L];
Console.WriteLine("Enter the Numbers :");
for (int i = 0; i < L; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
foreach (int x in a)
{
if (x == 1)
{
count++;
}
}
Console.WriteLine("Number of 1's in the Entered Number is : "+count);
}
catch (Exception ex)
{
Console.WriteLine("input is not in correct formate");
}
Console.ReadKey();
}
}
}
Enter the Limit :
4
Enter the Numbers :
1
2
1
5
Number of 1's in the Entered Number is : 2
0 टिप्पणियाँ