问题及代码:
运行结果:
分离三位数各个位数。
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:math.cpp
*作 者:单昕昕
*完成日期:2015年2月2日
*版 本 号:v1.0
*
*问题描述:输入一个三位数,分别输出它的百位十位个位
*输入描述:一个整数,是一个三位数
*程序输出:一个整数,代表三位数百位十位个位的值
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Math
{
class Program
{
static void Main(string[] args)
{
int a, x, y, z;
Console.Write("a = ");
a = int.Parse(Console.ReadLine());
x = a / 100;
y = a / 10 - 10 * x;
z = a % 10;
Console.WriteLine("百位:{0},十位:{1},个位:{2}",x,y,z);
Console.ReadKey();
}
}
}
运行结果:
分离三位数各个位数。
学习心得:
经典算法回顾。