适合初学者学习的C#编程代码(最基本程序代码)

 

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);
                }
 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值