编写ASP程式,计算并显示1到100的和。即:1+2+3+.100的和。

编写ASP程式,计算并显示1到100的和。即:1+2+3+.100的和。,第1张

编写ASP程式,计算并显示1到100的和。即:1+2+3+...100的和。

a=sum(1:100)

label0.capition=str$(a)

为任意数字(任意数字是指你那个标签的编号!)

1) 编写ASP程式,计算并显示1到100的奇数和。即:1+3+5...+99的和。 2)

<%

dim i,q,o

q=0

o=0

for i=1 to 50

q=q+2*i-1

next

for i=1 to 50

o=o+2*i

next

response.write "奇数1-99值"&q&",偶数2-100值"&o

%>

考场求援:编写一个辩春源asp程式,计算并显示1到100的奇数和。

楼上求的是偶数的和<%dim i,sum

sum=0

for i=1 to 99 step 2

sum=sum+inext

response.Write(sum)

%>

编写程式计算1+2+3+....+100的和.

public static void main(String[] args) {

int sum=0

for (int i = 1i <101i++) {

sum+=i

}

System.out.println(sum)

}

编写计算“1+2-3+...-99+100的和“的程式

也不知道你要用什么语言写,我就用C++写了方法有很多

int sum=1

for(int i=2i<=100i+=2)

sum+=i

for(int j=3j<100j+=2)

sum-=j

最后sum就是所求结果

编写Transact-SQL程式计算1+2+3+……+100的和

declare @n int,@sum int --宣告变数

select @n=100,@sum=0 --给变数赋值

while @n>0 begin --当@n的值为小于等于0时结束回圈

set @sum=@sum+@n --累加

set @n=@n-1 --回圈条件

end

select @sum --输出结果

编写程式计算SUM=1+1*2+1*2*3+……+1*2*3*…*100的和

#include<iostream>

using namespace std

int fac(int n)

{ double result=1

for(int i=2i<=ni++){result=result*i}

return result

}阶乘程式

int main()主程式

{

double sum=0

cout<<"sum="<<sum<<endl

for(int i=1i<=100i++){sum=sum+fac(i)}

cout<<"sum="<<sum<<endl

}

哎....,回答得太快了= =

编写程式计算从1到100的和。

用fortran语言做:

isum=0

do 10 i=1,100

10 isum=isum+i

write(*,*)'the sum of the number from 1 to 100 is:',isum

end

编写计算S=1+2+3+…+100的程式森颤。

用什么语言啊?如果是java的话就如下:

int s=0;

for(int i=1; i<=100;i++){

s=s+i;

}

补充

VFP:

s=0

for i=1 to 100

s=s+i

endfor

? s

编写程式,计算1+2+3+...+100

可以携态这样写:void main()

{ int sum=0

float i=1

do

{sum+=i<br/>i++<br/>}

while(i<=100)

printf("%d",sum)

}

<枯核html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

<title>Calculate</title>

<script language="VBSCRIPT">

Function Show(m)

If (Myform.Expression.Value = "" AND InStr(". + - * / ",m)) Then

Myform.Expression.Value = ""

ElseIf (InStr("+ - * / . ",Right(Myform.Expression.Value,1)) And InStr("+ - * / ",m)) Then

ElseIf (m = ".") Then

If (InStr("+ - * / . ",Right(Myform.Expression.Value,1))) Then

ElseIf ((InstrRev(Myform.Expression.Value,".") >InstrRev(Myform.Expression.Value,"+")) And (InstrRev(Myform.Expression.Value,".") >InstrRev(Myform.Expression.Value,"-")) And (InstrRev(Myform.Expression.Value,".") >InstrRev(Myform.Expression.Value,"*")) And (InstrRev(Myform.Expression.Value,".") >InstrRev(Myform.Expression.Value,"/"))) Then

Else

Myform.Expression.Value = Myform.Expression.Value + m

End If

Else

Myform.Expression.Value = Myform.Expression.Value + m

END If

End Function

Function Sqrt()

If (Myform.Expression.Value = "") Then

Myform.Expression.Value = ""

ElseIf (InStr(". + - * /余型 ",Right(Myform.Expression.Value,1))) Then

Else

Myform.Expression.Value = Eval(Myform.Expression.Value)^2

End If

End Function

Function Result()

If (Myform.Expression.Value = "") Then

Myform.Expression.Value = ""

ElseIf (InStr(". + - * / ",Right(Myform.Expression.Value,1))) Then

Else

Myform.Expression.Value = Eval(Myform.Expression.Value)

End If

End Function

Function Clean()

Myform.Expression.Value = ""

End Function

</script>

<style type="text/css">

<!--

.style5 {font-size: 18px}

-->

</style>

</head>

<body bgcolor="#ffffee" text=#000000>

<form name="myform" method="post" action="">

<div align="center">

<table bgcolor="#C0e0ff" width="214" height="245" border="4">

<tr>

<th width="206" scope="col"><H2><font color="#0000A0">计算器 </font></H2></th>

</tr>

<竖败猜tr>

<th height="36" scope="col"><table width="200" border="1">

<tr>

<td colspan="4"><div align="center">

<input name="expression" type="text" value="" size="28" maxlength="28" >

</div></td>

</tr>

<tr>

<td><div align="center">

<INPUT TYPE="button" id="seven"

onClick="Show('7')" VALUE=" 7 ">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 8 "

onClick="Show('8')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 9 "

onClick="Show('9')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" / "

onClick="Show('/')">

</div></td>

</tr>

<tr>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 4 "

onClick="Show('4')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 5 "

onClick="Show('5')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 6 "

onClick="Show('6')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" * "

onClick="Show('*')">

</div></td>

</tr>

<tr>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 1 "

onClick="Show('1')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 2 "

onClick="Show('2')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 3 "

onClick="Show('3')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" - "

onClick="Show('-')">

</div></td>

</tr>

<tr>

<td><div align="center">

<INPUT TYPE="button" VALUE=" 0 "

onClick="Show('0')">

</div></td>

<td><div align="center">

<INPUT TYPE="button" VALUE=" . "

onClick="Show('.')">

</div></td>

<td><div align="center">

<input type="button" value="sqr"

onClick="sqrt()">

</div></td>

<td><div align="center">

<input type="button" value=" + "

onClick="Show('+')">

</div></td>

</tr>

<tr>

<td colspan="2"><div align="center">

<INPUT TYPE="button" VALUE=" AC "

onClick="clean()">

</div></td>

<td colspan="2"><div align="center">

<INPUT TYPE="button" VALUE=" = "

onClick="result()">

</div></td>

</tr>

</table></th>

</tr>

</table>

</div>

</form>

</body>

</html>

贴首纤个最简单的吧:

Operation类腊棚:

class Operation

{

public static double GetResult(double numberA, double numberB, string operate)

{

double result = 0d

switch (operate)

{

case "+":

result = numberA + numberB

break

case "-":

result = numberA - numberB

break

case "*":

result = numberA * numberB

break

case "/":

result = numberA / numberB

break

}

return result

}

}

Program.cs:

class Program

{

static void Main(string[] args)

{

Console.WriteLine("请输入数字A:")

string strNumberA = Console.ReadLine()

Console.WriteLine("请输入运算符轮芹则号(+ - * /)")

string strOperate = Console.ReadLine()

Console.WriteLine("请输入数字B:")

string strNumberB = Console.ReadLine()

string strResult

strResult = Convert.ToString(Operation.GetResult(Convert.ToDouble(strNumberA), Convert.ToDouble(strNumberB), strOperate))

Console.WriteLine("结果是:" + strResult)

Console.ReadLine()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/yw/12348371.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存