用T-SQL编写求1到20的偶数之积和奇数之和的程序,并由print语句输出结果。 急急急,求高人啊
发布网友
发布时间:2022-04-24 03:23
我来回答
共2个回答
热心网友
时间:2023-10-24 16:39
declare @i int
set @i=1
declare @Total bigint
set @Total=1
declare @Sum int
set @Sum=0
while(@i<=20)
begin
if @i%2=0 set @Total=@Total*@i
else set @Sum=@Sum+@i
set @i=@i+1
end
print 'Total='+cast(@Total as varchar)
print 'Sum='+cast(@Sum as varchar)
结果如下:
Total=3715891200
Sum=100
热心网友
时间:2023-10-24 16:39
declare @i int
set @i=1
declare @Total bigint
set @Total=1
declare @Sum int
set @Sum=0
while(@i<=20)
begin
if @i%2=0 set @Total=@Total*@i
else set @Sum=@Sum+@i
set @i=@i+1
end
print 'Total='+cast(@Total as varchar)
print 'Sum='+cast(@Sum as varchar)
结果如下:
Total=3715891200
Sum=100
热心网友
时间:2023-10-24 16:40
忘了。。。也木有时间
热心网友
时间:2023-10-24 16:39
declare @i int
set @i=1
declare @Total bigint
set @Total=1
declare @Sum int
set @Sum=0
while(@i<=20)
begin
if @i%2=0 set @Total=@Total*@i
else set @Sum=@Sum+@i
set @i=@i+1
end
print 'Total='+cast(@Total as varchar)
print 'Sum='+cast(@Sum as varchar)
结果如下:
Total=3715891200
Sum=100
热心网友
时间:2023-10-24 16:40
忘了。。。也木有时间
热心网友
时间:2023-10-24 16:40
忘了。。。也木有时间
热心网友
时间:2023-10-24 16:39
declare @i int
set @i=1
declare @Total bigint
set @Total=1
declare @Sum int
set @Sum=0
while(@i<=20)
begin
if @i%2=0 set @Total=@Total*@i
else set @Sum=@Sum+@i
set @i=@i+1
end
print 'Total='+cast(@Total as varchar)
print 'Sum='+cast(@Sum as varchar)
结果如下:
Total=3715891200
Sum=100
热心网友
时间:2023-10-24 16:40
忘了。。。也木有时间