日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C语言程序100例之C#版-029

發布時間:2023/12/31 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言程序100例之C#版-029 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C語言程序100例之C#版-029

C程序源代碼:

【程序29】
題目:給一個不多于5位的正整數,要求:一、求它是幾位數,二、逆序打印出各位數字。
1. 程序分析:學會分解出每一位數,如下解釋:(這里是一種簡單的算法,師專數002班趙鑫提供)
2.程序源代碼:

#include "stdio.h" #include "conio.h" main( ) {long a,b,c,d,e,x;scanf("%ld",&x);a=x/10000;/*分解出萬位*/b=x%10000/1000;/*分解出千位*/c=x%1000/100;/*分解出百位*/d=x%100/10;/*分解出十位*/e=x%10;/*分解出個位*/if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld\n",e,d,c,b,a);else if (b!=0) printf("there are 4, %ld %ld %ld %ld\n",e,d,c,b);else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c);else if (d!=0) printf("there are 2, %ld %ld\n",e,d);else if (e!=0) printf(" there are 1,%ld\n",e);getch(); }


########################

C#語言程序:

using System; class C329 {static void Main(){long a,b,c,d,e,x;x=Convert.ToInt64(Console.ReadLine());a=x/10000;b=x%10000/1000;c=x%1000/100;d=x%100/10;e=x%10;if (a!=0) Console.Write("there are 5, {0} {1} {2} {3} {4}\n",e,d,c,b,a);else if (b!=0) Console.Write("there are 4, {0} {1} {2} {3}\n",(int)e,(int)d,(int)c,(int)b);else if (c!=0) Console.Write(" there are 3,{0} {1} {2}\n",(int)e,(int)d,(int)c);else if (d!=0) Console.Write("there are 2, {0} {1}\n",(int)e,(int)d);else if (e!=0) Console.Write(" there are 1,{0}\n",(int)e);} }



擴展1:平時寫應用是,如果純粹為了實現目標進行分解和倒序,可以考慮用字符串來處理,方便,快捷。但處理過程不是以數值計算的方式來實現的。

using System; class C329_1 {static void Main(){long x;x=Convert.ToInt64(Console.ReadLine());String y = x.ToString();Console.Write("there are" + x.ToString().Length+",");for (int i = 1; i <= y.Length; i++){Console.Write(y.Substring(y.Length - i, 1));Console.Write(" ");}} }


擴展2:保持數值計算,(原題目要求為不多余5位的正整數)并且擴展輸入數據長度(但不能超過所使用的數值類型的最大長度);

using System; using System.Collections.Generic;class C329_2 {static void Main(){long x;x=Convert.ToInt64(Console.ReadLine());String y = x.ToString();int z = x.ToString().Length;Console.Write("there are " + z+",");int a = 10;int b = 0;int c = (int)x;List<int> d = new List<int>();for (int i = y.Length-1; i >= 0; i--){b = (int)Math.Pow(a, i);d.Add(c / b);c = (int)x % b;}d.Reverse();for (int i = 0; i < d.Count;i++ ){Console.Write(d[i]);Console.Write(" ");}} }

總結

以上是生活随笔為你收集整理的C语言程序100例之C#版-029的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。