我在开始学习c#。下面一个程序的两个版本怎么结果不一样?
正确.version
using System;class Test{ static void divide(int a,int b,out int result,out int
remainder){ result=a/b; remainder=a%b; } static void Main(){ for(int i=1;i<10;i++) for(int j=1;j<10;j++){ int ans,r; divide(i,j,out ans,out r); Console.WriteLine("{0}/{1}={2},{3}%{4}={5}",i,j,ans,i,j,r); } Console.ReadLine();} }
运行结果:1/1=1,1%1=01/2=0,1%2=11/3=0,1%3=11/4=0,1%4=11/5=0,1%5=11/6=0,1%6=11/7=0,1%7=11/8=0,1%8=11/9=0,1%9=12/1=2,2%1=02/2=1,2%2=02/3=0,2%3=22/4=0,2%4=22/5=0,2%5=22/6=0,2%6=22/7=0,2%7=22/8=0,2%8=22/9=0,2%9=23/1=3,3%1=03/2=1,3%2=13/3=1,3%3=03/4=0,3%4=33/5=0,3%5=33/6=0,3%6=3
错误.version
using System;class Test{ static void divide(int a,int b,out int result,out int remainder){ result=a/b; remainder=a%b; } static void Main(){ for(int i=1;i<10;i++) for(int j=1;j<10;j++){ int ans,r; divide(i,j,out ans,out r); Console.WriteLine("{0}/{1}={2},{0}%{1}={3}",i,j,ans,i,j,r);//改动处 } Console.ReadLine();} }运行结果:1/1=1,1%1=11/2=0,1%2=11/3=0,1%3=11/4=0,1%4=11/5=0,1%5=11/6=0,1%6=11/7=0,1%7=11/8=0,1%8=11/9=0,1%9=12/1=2,2%1=22/2=1,2%2=22/3=0,2%3=22/4=0,2%4=22/5=0,2%5=22/6=0,2%6=22/7=0,2%7=22/8=0,2%8=22/9=0,2%9=23/1=3,3%1=33/2=1,3%2=33/3=1,3%3=33/4=0,3%4=33/5=0,3%5=33/6=0,3%6=33/7=0,3%7=33/8=0,3%8=33/9=0,3%9=34/1=4,4%1=44/2=2,4%2=44/3=1,4%3=44/4=1,4%4=44/5=0,4%5=44/6=0,4%6=44/7=0,4%7=44/8=0,4%8=44/9=0,4%9=45/1=5,5%1=55/2=2,5%2=55/3=1,5%3=55/4=1,5%4=55/5=1,5%5=55/6=0,5%6=55/7=0,5%7=55/8=0,5%8=55/9=0,5%9=56/1=6,6%1=66/2=3,6%2=66/3=2,6%3=66/4=1,6%4=66/5=1,6%5=66/6=1,6%6=66/7=0,6%7=66/8=0,6%8=66/9=0,6%9=67/1=7,7%1=77/2=3,7%2=77/3=2,7%3=77/4=1,7%4=77/5=1,7%5=77/6=1,7%6=77/7=1,7%7=77/8=0,7%8=77/9=0,7%9=78/1=8,8%1=88/2=4,8%2=88/3=2,8%3=88/4=2,8%4=88/5=1,8%5=88/6=1,8%6=88/7=1,8%7=88/8=1,8%8=88/9=0,8%9=89/1=9,9%1=99/2=4,9%2=99/3=3,9%3=99/4=2,9%4=99/5=1,9%5=99/6=1,9%6=99/7=1,9%7=99/8=1,9%8=99/9=1,9%9=9为什么会出现这种问题?