寰幆璇彞
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寰幆璇彞相关的知识,希望对你有一定的参考价值。
鏍囩锛?/p>
for
鏍煎紡锛?/p>
for (int i = 1/*鍒濆鏉′欢*/; i <= 100/* 寰幆鏉′欢*/; i++ /*鐘舵€佹敼鍙?/)
{
//寰幆浣擄紝鎵ц浠g爜锛?break;璺冲嚭寰幆浣?
}
缁欏嚭鍒濆鏉′欢锛屽厛鍒ゆ柇鏄惁婊¤冻寰幆鏉′欢锛屽鏋滀笉婊¤冻鏉′欢鍒欒烦杩噁or璇彞锛屽鏋滄弧瓒冲垯杩涘叆for璇彞鎵ц锛宖or璇彞鍐呯殑浠g爜鎵ц瀹屾瘯鍚庯紝灏嗘寜鐓х姸鎬佹敼鍙橈紝鏀瑰彉鍙橀噺锛岀劧鍚庡垽鏂槸鍚︾鍚堝惊鐜潯浠讹紝绗﹀悎鍒欑户缁墽琛宖or璇彞鍐呯殑浠g爜锛岀洿鍒板彉閲廼涓嶇鍚堝惊鐜潯浠跺垯缁堟寰幆锛屾垨鑰呯鍒癰reak;鍛戒护锛岀洿鎺ヨ烦鍑哄綋鍓嶇殑for寰幆銆?/p>
break鍦ㄨ繖閲屾槸璺冲嚭寰幆鐨勬剰鎬濄€?/p>
for鍙互宓屽銆?/p>
渚嬶細
涓€涓父鎴忥紝鍓?0鍏虫槸姣忎竴鍏宠嚜韬殑鍒嗘暟锛?br /> 21-30鍏虫瘡涓€鍏虫槸10鍒?br /> 31-40鍏筹紝姣忎竴鍏虫槸20鍒?br /> 41-49鍏筹紝姣忎竴鍏虫槸30鍒?br /> 50鍏筹紝鏄?00鍒?br /> 杈撳叆浣犵幇鍦ㄩ棷鍒扮殑鍏冲崱鏁帮紝姹備綘鐜板湪鎷ユ湁鐨勫垎鏁?br /> 涓ょ鍋氭硶锛歩f宓屽for for宓屽if
1.if宓屽for
Console.WriteLine("杈撳叆鍏冲崱");
int a = int.Parse(Console.ReadLine());
int b = 0;
if (a <= 50 && a > 0)
{
if (a <= 20)
{
for (int n = 0; n <= a; n++)
{
b = b + n;
}
}
else if (a <= 30)
{
for (int n = 0; n <= 20; n++)
{
b = b + n;
}
for (int n = 21; n <= a; n++)
{
b = b + 10;
}
}
else if (a <= 40)
{
for (int n = 0; n <= 20; n++)
{
b = b + n;
}
for (int n = 21; n <= 30; n++)
{
b = b + 10;
}
for (int n = 31; n <= a; n++)
{
b = b + 20;
}
}
else if (a <= 49)
{
for (int n = 0; n <= 20; n++)
{
b = b + n;
}
for (int n = 21; n <= 30; n++)
{
b = b + 10;
}
for (int n = 31; n <= 40; n++)
{
b = b + 20;
}
for (int n = 41; n <= a; n++)
{
b = b + 30;
}
}
else
{
for (int n = 0; n <= 20; n++)
{
b = b + n;
}
for (int n = 21; n <= 30; n++)
{
b = b + 10;
}
for (int n = 31; n <= 40; n++)
{
b = b + 20;
}
for (int n = 41; n <= 49; n++)
{
b = b + 30;
}
for (int n = 50; n <= a; n++)
{
b = b + 100;
}
}
Console.WriteLine("鍒嗘暟鏄? + b);
}
else
{
Console.WriteLine("杈撳叆鏈夎");
}
Console.ReadLine();
2.for宓屽if
Console.WriteLine("杈撳叆鍏冲崱");
int a = int.Parse(Console.ReadLine());
int b = 0;
if (a <= 50 && a > 0)
{
for (int n = 0; n <= a; n++)
{
if (n <= 20)
{
b = b + n;
}
else if (n <= 30)
{
b = b + 10;
}
else if (n <= 40)
{
b = b + 20;
}
else if (n <= 49)
{
b = b + 30;
}
else
{
b = b + 100;
}
}
Console.WriteLine("鍒嗘暟鏄? + b);
}
else
{
Console.WriteLine("杈撳叆鏈夎");
}
Console.ReadLine();
for宓屽
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("鈻?);
}
Console.WriteLine();
}
Console.ReadLine();
鈻?/span>
鈻?鈻?/span>
鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?鈻?/span>
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= (5 - i) + 1; j++)
{
Console.Write("鈻?);
}
Console.WriteLine();
}
Console.ReadLine();
鈻?鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?/span>
鈻?鈻?/span>
鈻?/span>
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j < i; j++)
{
Console.Write(" ");
}
for (int k = 1; k <= (5 - i) + 1; k++)
{
Console.Write("鈻?);
}
Console.WriteLine();
}
Console.ReadLine();
鈻?鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?/span>
鈻?鈻?/span>
鈻?/span>
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5 - i; j++)
{
Console.Write(" ");
}
for (int h = 1; h <= i; h++)
{
Console.Write("鈻?);
}
Console.WriteLine();
}
Console.ReadLine();
鈻?/span>
鈻?鈻?/span>
鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?/span>
鈻?鈻?鈻?鈻?鈻?/span>
以上是关于寰幆璇彞的主要内容,如果未能解决你的问题,请参考以下文章
linq to sql 鍜?entity framework 杈撳嚭sql璇彞