C# Program toward solve different problems
Program Statement:
Write a program which will take input a character ‘a’ value from user. You have toward use switch statement toward decide if value regarding a is ‘t’ then you have toward call table function, if value regarding a is ‘f’ then call factorial function, if value regarding a is ‘p’ then call prime function, if value regarding a is ‘s’ then call search function.
You have toward write four functions in your program;
Search(char n5[], char c, char choice)
Table function will print the table regarding n1 from 1 toward n2.
Factorial function will print the factorial regarding n3 if n3 is multiple regarding 2.
Prime function will print the n4 if n4 is prime.
Search function will take first argument n5 as an array regarding characters furthermore second element a character toward be search in the array furthermore third element a character toward decide which searching algorithm toward be used.i.e. if user has passed the value regarding c as ‘s’ then Search function will perform the sequential search but if value regarding c is something else then Search function will perform binary search.
Structure regarding your program will be like this. You have toward make it exactly working.
class functions
{
public int fact = 1;
public void factorial(int n3)
{
if (n3 % 2 == 0)
{
beneficial to (int i = 1; i <= n3; i++)
{
fact = fact * i;
}
Console.WriteLine("\n\t\tFactorial is : {0}\n\n", fact);
}
else
{
Console.WriteLine("\n\t\tIts not multiple regarding 2!\n\t\t");
}
}
public void prime(int n4)
{
int i = 2;
if (n4 == 1)
{
Console.WriteLine("Number is not prime!");
}
beneficial to (i = 2; i <= n4 - 1; i++)
{
if (n4 % i == 0)
{
Console.WriteLine("Number is not prime!");
break;
}
}
if (n4 == i)
{
Console.WriteLine("{0} is a prime number!", n4);
}
}
public void table(int n1, int n2)
{
beneficial to (int i = 1; i <= n2; i++)
{
Console.WriteLine("{0} * {1} = {2}", n1, i, n1 * i);
}
}
public void search(char[] array, char s)
{
int p = 0;
foreach (char c in array)
{
if (c == s)
{
Console.WriteLine("Character {0} found!", c);
p++;
break;
}
}
if (p == 0)
Console.WriteLine("character not found.");
}
}