We wil try with some Basic use of Functions in Console using c#
class abc
{
static void Main()
{
MyDetails("ashir","tangori","b.tech");
string a=System.Console.ReadLine();
string b=System.Console.ReadLine();
string c=System.Console.ReadLine();
MyDetails(a,b,c);
}
static void MyDetails(string nm,string clge,string dgre)
{
System.Console.WriteLine("the name is {0}",nm);
System.Console.WriteLine("college is {0}",clge);
System.Console.WriteLine("degree is {0}",dgre);
}
}
2)Simple addition using functions
class abc
{
static void Main()
{
int x=Sum(7,8);
System.Console.WriteLine("the sum is {0}",x);
}
static int Sum(int a,int b)
{
int y=a+b;
return(y);
}
}
3) Program to check discount using functions
class abc
{
static void Main()
{
int a;
float b;
System.Console.WriteLine("enter quantity");
a=System.Convert.ToInt32(System.Console.ReadLine());
System.Console.WriteLine("Enter price");
b=System.Convert.ToSingle(System.Console.ReadLine());
float c=DiscountedAmount(a,b);
System.Console.WriteLine("The net Price is {0}",c);
}
static int DiscountedAmount(int quan,float price)
{
float total=quan*price;
if(total<10000)
{
float dis=total*5/100;
float net=total-dis;
int a=System.Convert.ToInt32(net);
return(a);
}
else if(total>10000 && total<15000)
{
float dis=total*10/100;
float net=total-dis;
int a=System.Convert.ToInt32(net);
return(a);
}
else if(total>15000 && total<20000)
{
float dis=total*15/100;
float net=total-dis;
int a=System.Convert.ToInt32(net);
return(a);
}
else
{
float dis=total*20/100;
float net=total-dis;
int a=System.Convert.ToInt32(net);
return(a);
}
}
}
No comments:
Post a Comment