The sum of digits

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

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. The Modulo operator can be used to get the last digit of a number in base 10. Given a five-digit integer, print the sum of its digits.

Input Format

The input contains a single five-digit number.

Output Format

Print the sum of the digits of the five-digit number.

Constraints

10,000 <= n <= 99,999

C Program

#include <stdio.h>
#include <stdlib.h>
int main() {
int n, sum=0,rem;
scanf("%d", &n); //Enter the number
while(n>0)
{
sum=sum+(n%10); //Calculating the sum
n/=10; //Removing the last digit
}
printf("%d\n",sum);
return 0;
}

Related Posts

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

HTML Cheatsheet

Unleash your web development potential with my HTML cheatsheet! Elevate your coding skills, master essential tags and attributes, and build stunning websites with ease. Whether you’re a…

Git&GitHub Cheatsheet

Elevate your Git and GitHub game with my ultimate cheatsheet! Unlock the power of version control, streamline collaboration, and boost productivity. Navigate the complexities of Git commands…

Command Line Cheatsheet

Master the Command Line effortlessly with my comprehensive cheatsheet! Streamline your workflow, boost productivity, and become a command line guru. Unlock essential commands, shortcuts, and tips to…

OpenAI’s APIs Notes

Unlock the potential of OpenAI’s APIs with my comprehensive notes! Dive into the world of cutting-edge artificial intelligence, explore the capabilities of GPT-4 and beyond, and learn…

SQL Notes

Discover the essence of SQL with my comprehensive notes! Dive into the world of Structured Query Language, unraveling the complexities, and mastering database management. Elevate your SQL…

Leave a Reply

Your email address will not be published. Required fields are marked *