练习1:输出10句Hello World
int pi = 0;
while(pi<10){
Console.WriteLine ("Hello World");
pi++;
}
练习2:累加1-100的和
int sum = 0;
int intNum = 1;
while(intNum<=100){
sum += intNum;
intNum++;
}
Console.WriteLine (sum);
练习3:输出1-100之间的所有偶数和
int a = 1;
int intSum = 0;
while(a<=100){
if(a%2==0){
intSum +=a;
}
a++;
}
Console.WriteLine (intSum);
练习4:输出1-100之间的所有数字
int i = 1;
while(i<=100){
Console.WriteLine (i);
i++;
}
// 练习5:输出1-100之间所有能整除4的数
int a = 1;
while(a<=100){
if(a%4==0){
Console.WriteLine (a);
}
a++;
}
练习6:输出1-100之间所有的奇数和
int a =1 ;
int intSum = 0;
while(a<=100){
intSum += a;
if(a%2 !=0){
intSum +=a;
}
a++;
}
Console.WriteLine (intSum);
int stuNumber = new Random().Next(1,18);
Console.WriteLine ("请{0}号",stuNumber);
练习7:输出1~100之间所有能被三整除但是不能被4整除的所有奇数
int a = 1;
do{
if(a%2 !=0){
if(a%3 ==0 && a%4 !=0){
Console.WriteLine (a);
}
}
}while(a<=100);
练习8 求和1~100使用for循环
int sum = 0;
for (int i = 1; i <= 100; i++) {
sum = sum+i;
Console.WriteLine (i);
}
// 练习9:输出1~100之间所有的奇数
for (int i = 1; i <= 100; i++) {
if(i%2 !=0){
Console.WriteLine (i+" ");
}
}
// 练习10:打印000-999之间所有的数字
for (int i = 0; i <10 ; i++) {
for (int j = 0; j <10 ; j++)
for (int k = 0; k <10 ; k++) {
Console.WriteLine ("{0},{1}.{2}",i,j,k);
}
}
// 练习11:打印9*9乘法表
Console.WriteLine ("九九乘法表");
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
Console.Write ("{0}x{1}={2}\t ",i,j,i*j);
}
Console.WriteLine ();
}