| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4270 人关注过本帖
标题:用c#语言如何实现一个数的n次方?
只看楼主 加入收藏
shenying
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-24
收藏
 问题点数:0 回复次数:7 
用c#语言如何实现一个数的n次方?
用c#语言如何实现一个数的n次方?
搜索更多相关主题的帖子: 语言 
2005-03-24 20:56
bingxue
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-3-23
收藏
得分:0 
using System;
class My
{
 static void Main()
 {
  int a,b=1;
  int n;
  Console.WriteLine("please input n :");
  n=int.Parse(Console.ReadLine());//n是次方
  Console.WriteLine("please input a :");
  a=int.Parse(Console.ReadLine());//a是那个数
  for(int i=1;i<=n;i++)
  {
   b=b*a;
  }
  Console.WriteLine(a+"的"+n+"次方是:"+b);
 }
}

           写的不好不要见笑呀.

2005-03-24 22:36
jacky
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2004-12-17
收藏
得分:0 
using System;
public class Square
{
 public static void Main()
 {
  int x,y;
  Console.WriteLine ("Input n:");
        x=int.Parse (Console.ReadLine ());
  Console.WriteLine ("Input a:");
  y=int.Parse (Console.ReadLine ());
  double m=Math.Pow (y,x);
  Console.WriteLine (y+"的"+x+"的次方是"+m);
 }
}
2005-03-25 07:17
shenying
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-24
收藏
得分:0 
很好,谢谢!! http://guanggaojiaoyu.nease.net/

2005-03-25 07:36
tianhe
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2005-3-17
收藏
得分:0 
shenying兄:试试这个应该行的。jacky的方法更好点。
using System;
 class pingfang
 {
 static private int sum=1;
  static void Main()
  {
   Console.WriteLine("Please input times");
   int iRead1=int.Parse(Console.ReadLine());
   Console.WriteLine("please input number");
   int iRead2=int.Parse(Console.ReadLine());
   for(int i=1;i<=iRead1;i++)
   {
    sum=sum*iRead2;
   
   }
   Console.WriteLine("The pingfang is"+sum);
  }
 }

-------------------------------------------- 朴素,清醒
2005-03-25 10:32
adm_qxx
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2005-4-5
收藏
得分:0 

试一试这个函数:

Math.Pow(底数,指数):


学习是进步的基础.
2005-04-05 09:15
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
二楼和五楼的主语句都不对哦。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-05 09:31
shenying
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-24
收藏
得分:0 
谢谢
我已经做出来了,谢谢,不过没分可奖了,谢谢回服!!!

2005-04-29 20:41
快速回复:用c#语言如何实现一个数的n次方?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012072 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved