Skip to main content

Sum of Digits of a Five Digit Number

 Sum of Digits of a Five Digit Number



Objective

The modulo operator,%, returns the remainder of a division. For example, 4 % 3 = 1 and 12 % 10 = 2. The ordinary division operator, /, returns a truncated integer value when performed on integers. For example, 5 / 3 = 1. To get the last digit of a number in base 10, use as the modulo divisor.

Task

Given a five-digit integer, print the sum of its digits.

Input Format

The input contains a single five digit number, .

code-

#include <stdio.h>
int main() 
{
  int num;
  int digit;
  int sum=0;
  scanf("%d", &num);
  
  while(num>0)
  {
    digit = num % 10;
    sum = sum+digit;
    num = num / 10;
  }
  printf("%d",sum);
return 0; 
}

Comments

Popular posts from this blog

Top 10 Secure Computing Tips

Top 10 Secure Computing Tips:-   "Top 10" List of Secure Computing Tips Tip #1 - You are a target to hackers Don't ever say, "It won't happen to me." We are all at risk and the stakes are high - both for your personal and financial well-being and for the university's standing and reputation.  Cybersecurity is everyone's responsibility. By following the tips below and remaining vigilant, you are doing your part to protect yourself and others. Tip #2 - Keep software up-to-dat e Installing software updates for your operating system and programs is critical. Always install the latest security updates for your devices: Turn on Automatic Updates for your operating system. Use web browsers such as Chrome or Firefox that receive frequent, automatic security updates . Make sure to keep browser plug-ins (Flash, Java, etc.) up-to-date. Tip #3 - Avoid Phishing scams - beware of suspicious emails and phone calls Phishing scams are a constant threat - using variou...

C Program to Check Year is a Leap Year or Not

How to Check Year is a Leap Year or Not in C:- In this program we have to find the year is a leap year or not. Generally  we assume that year is exactly divisible by 4 is a leap year. But it is not only in this case 1900 is divisible by 4. But it  is not a leap so it that case we follows these conditions    It is exactly divisible by 100 If it is divisible by 100, then it should also exactly divisible by 4 And it is divisible by 400   These all conditions are true year is a leap year. ALGORITHMS:- Step 1 . Initialize variable “year” to find leap year. Step 2 . Take input from User. Step 3 . We use this condition ((year%4==0)&&            (year%100!=0)) || (year%400==0)) to check the year is Leap or not. S tep 4 . It is true display year i...

Calculate the sum of elements in an array.

  HOW TO CALCULATE THE SUM OF THE ELEMENT IN A GIVEN ARRAY: - We will learn how to find the sum of elements in an array is an easy task when you know how to iterate through array elements. In this problem, we will explain your C approach to find the sum of array elements inputted by the user. Here is the solution to this query in C Languageguage.   ALGORITHMS: STEP 1:-   Input the size of the array and store the value in m and arr[m]. STEP 2 : - To store the sum of array elements, initialize a variable sum = 0. STEP 3: -To find the sum of all elements, iterate through each element  and add the current element to the sum. STEP 4: - Inside the loop add the current array element to sum i.e.                 sum = sum + arr[i] or sum += arr[i]. CODE:- #include <stdio.h> int  main() {      int  i,num,a[ 100 ],sum= 0 ;     printf( "Enter the value of number:...