c# - Write a program which will input a 4 digit number from the user and then print the first and 2nd last digit of the number? -
write program input 4 digit number user , print first , 2nd last digit of number .... can reverse 4 numbers can't this..
assuming entered number 4 digit number.
class program { static void main(string[] args) { int num, sum = 0, r,pos = 0; console.writeline("enter number : "); num = int.parse(console.readline()); while (num != 0) { pos++; r = num % 10; num = num / 10; if(pos == 0)||(pos==2){ console.writeline("digit at"+ pos + "is : "+r); } } console.readline(); } }
Comments
Post a Comment