Thursday, 24 December 2020

Write a program to find the sum of all the digits of a number using while statement.

#include <iostream>

using namespace std;

main()

{

  int N,d,Sum=0;

  cout<<"Enter a Number\n";

  cin>>N;

  while(N>0)

  {

    d=N%10;

    Sum=Sum+d;

    N=N/10;

  }

  cout<<"Sum= "<<Sum;

}


No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...