using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 作业题
{
class Program
{
static void Main(string[] args)
{
/* 1.计算b,当a>=100时b=a;当a<100时b=2*a-1.
double a, b;
a = double.Parse(Console.ReadLine());
if (a<=100)
b=2*a+1;
else
b=a;
Console.WriteLine ("请输入:{0},结果是:{1}",a,b);
2.将int类型转化为text类型
int a = 123;
TextBox1.Text = a.ToString();
3. 将char类型转化为int类型
char ch = '9';
int i = (int)ch;
Console.WriteLine(ch);
4.将str类型转化为int类型
string str = "123";
int i = int.Parse(str);
Console.WriteLine(str);
5.圆的面积和周长
const double PI = 3.14;
double r = double.Parse(Console.ReadLine());
double s = PI * r * r;
double L = 2 * PI * r;
Console.WriteLine("圆的面积是{0},圆的周长是{1}", s, L);
6.求绝对值
double x, y;
x = double.Parse(Console.ReadLine());
if (x >= 0)
y = x;
else
y = -x;
Console.WriteLine("{0}的绝对值是{1}", x, y);
7)久久乘法表倒过来
int i = 9;
while (i >= 1)
{
int j = 1;
while (j <= i)
{
Console.Write("{0}*{1}={2} ", j, i, j * i);
j++;
}
Console.WriteLine(" ");
i--;
}
7)久久乘法表
int i=1;
while (i <= 9)
{
int j = 1;
while (j <= i)
{
Console.Write("{0}*{1}={2}", j, i, j * i);
j++;
}
Console.WriteLine(" ");
i++;
}
8)}用do--while语句计算从1到100的和
int n=1,sum=0;
do
{
sum+=n;
}
while(n++<100);
Console.WriteLine ("从1到100的和是{0}",sum );
Console.WriteLine ("n的值是{0}",n );
9)for循环从1加到100的和
int s = 0;
for (int i = 1; i <= 100; i++)
{
s = s + i;
}
Console.WriteLine(s);
10)久久乘法表(for循环)
for ( int i=1;i<= 9; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0}*{1}={2} ", j, i, i * j);
}