Tampilkan postingan dengan label function. Tampilkan semua postingan
Tampilkan postingan dengan label function. Tampilkan semua postingan

Jumat, 13 Mei 2016

C Main Function for Calling all classes

C# Main Function for Calling all classes

 void Main_Fun()
{
int num;
Program obj = new Program();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.WriteLine(" *****VISUAL PROGRAMMING*****");
Console.WriteLine(" ****ASSIGNMENT # 1**** ");
Console.Write(" If Run Project (Y/N) ? ");
obj.choice = Convert.ToChar(Console.ReadLine());
if (obj.choice != Y && obj.choice != y)
{
Console.WriteLine(" See you Next Time");
}
else
{
Console.Write(" Enter the Question No. : ");
num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
obj.Question_1();
break;
case 2:
obj.Question_2();
break;
case 3:
obj.Question_3();
break;
case 4:
obj.Question_4();
break;
case 5:
obj.Question_5();
break;
case 6:
obj.Question_6();
break;
case 7:
obj.Question_7();
break;
case 8:
obj.Question_8();
break;
case 9:
obj.Question_9();
break;
case 10:
obj.Question_10();
break;
case 11:
obj.Question_11();
break;
case 12:
obj.Question_12();
break;
case 13:
obj.Question_13();
break;
case 14:
obj.Question_14();
break;
case 15:
obj.Question_15();
break;
case 16:
obj.Question_16();
break;
case 17:
obj.Question_17();
break;
case 18:
obj.Question_18();
break;
case 19:
obj.Question_19();
break;
case 20:
obj.Question_20();
break;
case 21:
obj.Question_21();
break;
case 22:
obj.Question_22();
break;
case 23:
obj.Question_23();
break;
case 24:
obj.Question_24();
break;
case 25:
obj.Question_25();
break;
case 26:
obj.Question_26();
break;
case 27:
obj.Question_27();
break;
case 28:
obj.Question_28();
break;
case 29:
obj.Question_29();
break;
case 30:
obj.Question_30();
break;
case 31:
obj.Question_31();
break;
case 32:
obj.Question_32();
break;
case 33:
obj.Question_33();
break;
case 34:
obj.Question_34();
break;
case 35:
obj.Question_35();
break;
case 36:
obj.Question_36();
break;
case 37:
obj.QUestion_37();
break;
case 38:
obj.Question_38();
break;
case 39:
obj.Question_39();
break;
case 40:
obj.Question_40();
break;
case 41:
obj.Question_41();
break;
case 42:
obj.Question_42();
break;
case 43:
obj.Question_43();
break;
case 44:
obj.Question_44();
break;
case 45:
obj.Question_45();
break;
default:
Console.WriteLine(" Invalid Program Number Try Again");
break;
}
}
}


Kamis, 14 April 2016

C Program using Two argument passing function

C# Program using Two argument passing function

Program Statement:
Write a function which takes two values n1 and n2 as arguments and multiply the n1 by itself n2 times i.e. calculate n1n2 and then return the result to main function which will display the result.

Solution:
 class power_fun
{
double x;
public
power_fun()
{
x = 1;
}
double power(int a,int b)
{

for (int i = 1; i <= b; i++)
{
x = x * a;
}
return x;
}

static void Main(string[] args)
{
power_fun p = new power_fun();
int n1, n2;
double result;
Console.Write("Enter 1st Value: ");
n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter 2nd Value: ");
n2 = Convert.ToInt32(Console.ReadLine());
result= p.power(n1, n2);
Console.WriteLine(n1+"^ "+ n2+" = "+ result);
Console.ReadLine();
}


Jumat, 11 Maret 2016

C Program which calculated factorial to prime function

C# Program which calculated factorial to prime function

Program Statement:
Write two functions max(int,int) and prime(int). max function will take two arguments and will return the maximum of two numbers in main. Then main function will pass this calculated factorial to prime function which will show that passed value is prime or not.

Solution:
 public class _max
{
public int max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
public void prime(int n)
{
if (n == 1)
Console.WriteLine(" {0} is maximum but not prime number! ", n);
if (n >= 2)
{
if (n % 2 != 0)
{
Console.WriteLine(" {0} is maximum and Prime number! ", n);
}
else
{ Console.WriteLine(" {0} is maximum but not a Prime number! ", n); }
}
}
}


 

Tips And Trick Computer Copyright © 2016 -- Powered by Blogger