6.1
static double f(int n)
{
double i = 1;
double sum =0;
while (i<=n)
{
sum += 1/i;
i++;
}
return sum;
}
6.2
int sum = 1;
while (n>0)
{
sum *= n;
n= n-1;
}
return sum;
6.3
double j = 0;
double sum = 0;
while (j<=k)
{
sum += 1/(double)(Factorial((int)j));
j++;
}
return sum;
7
using System;
class x
{
static int f(int n)
{
double sum = 20+10*Math.Sin(n/Math.PI);
int sum1 = (int)Math.Round(sum);
return sum1;
}
static void PlotChar(int a , int b)
{
int i = 1;
while (i<b)
{
Console.Write(" ");
i++;
}
Console.WriteLine("*");
}
static void Main()
{
Console.WriteLine(" x|");
Console.WriteLine("--+---------------------------------------> y");
int i = 0;
while (i<=20)
{
Console.Write("{0,2}|",i);
PlotChar(' ',f(i));
i++;
}
Console.Read();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น