Tech Study

Write C# program to print sum of digits enter by user

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class csharpExercise
{
    static void Main(string[] args)
    {
 
        int num, total;
 
        //Reading number
        Console.WriteLine("Enter any number: ");
        num = Convert.ToInt32(Console.ReadLine());
 
        //Adding sum of digit in total variable
        for (total = 0; num > 0; num = num / 10)
            total = total + (num % 10);
 
        //Printing sum of digit
        Console.WriteLine("Sum of digits: "+ total);
 
        Console.ReadLine();
    }
}

Result

Write C# program to print sum of digits enter by user
Write C# program to print sum of digits enter by user

TaggedWrite C++ program to print sum of digits enter by user

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more