Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Напишете програма която приема вход от клавиатурата положително число n и
- отпечатва сумата на цифрите от които е съставено въведеното число. */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Loops_Homework
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("n = ");
- int n =Int32.Parse (Console.ReadLine());
- int sum = 0;
- while (n > 0)
- {
- int digit = n % 10;
- n /= 10;
- sum += digit;
- }
- Console.WriteLine("sum = {0}" ,sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment