DEV Community

Dot Net By Vickypedia
Dot Net By Vickypedia

Posted on

Factorial of a number

Step 1: Open Visual Studio and select console application.
Step 2: Write a Program to find occurrence of character in string

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

namespace CharacterOccurrenceApp
{
class Program
{
static void Main(string[] args)
{
string Statement = string.Empty;

        Console.WriteLine("Enter a string to check occurrence of a character numbers");

        Statement = Console.ReadLine();
        Statement = Statement.ToLower();

        if (Statement.Length > 0)
        {
            while (Statement.Length > 0)
            {
                int CountCharacter = 0;
                Console.Write("Number of Occurance of '" + Statement[0] + "': ");

                //Checking the Character occurrence in the string entered by the user
                for (int i = 0; i < Statement.Length; i++)
                {
                    if (Statement[0] == Statement[i])
                    {
                        CountCharacter++;
                    }
                }

                //Count of each character
                Console.Write(CountCharacter + "\n");

                //Removing that character from the string
                Statement = Statement.Replace(Statement[0].ToString(), string.Empty);
            }
        }
        Console.ReadLine();
    }
}

}

Step 3 : Run the application then console will be open.
Step 4: Enter the string then press "Enter" key then see the output.

Top comments (0)