Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone
HackerRank Sum of Digits of a five digit number solution in c

HackerRank Sum of Digits of a Five Digit Number solution in c

YASH PAL, 15 July 202416 January 2026

HackerRank Sum of Digits of a Five Digit Number solution in C – In this tutorial we are going to solve the HackerRank Sum of Digits of a five-digit number problem or write a program for that. In this problem we need to take an input of a five-digit number that is always greater than 10000 and less than 99999. and on the output screen, we need to print the sum of that 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 10 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, n.

Constraints

10000 <= n <= 99999

Output Format

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

Logic – How are we going to calculate the sum?

Let say we have a digit 45644 and if we module this number by 10 then we get the last digit of the number that 4 means 45644%10 then the remainder is 4. After the division by 10 45644/10 we get the remaining 4 digits 4564. we will use this logic five times and will sum the reminder and we will get the sum of 5 digit number. Similarly, we can apply this logic to any length of number.

HackerRank Sum of Digits of a five digit number solution in c
HackerRank Sum of Digits of a five digit number solution in c

Sum of Digits of five digit number solution in C

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
	
    int n;
scanf("%d", &n);
int digit, temp, sum = 0;
temp = n;
//Complete the code to calculate the sum of the five digits on n.
while(temp > 0)
{
    digit = temp % 10;
    sum = sum + digit;
    temp = temp / 10;
}
printf("%d\n",sum);
return 0;
}

Next problem solution – HackerRank Bitwise operators in C Solution

C Solutions coding problems solutions Hackerrank Problems Solutions cHackerRank

Post navigation

Previous post
Next post

Comment

  1. Senuke Proxy says:
    24 December 2025 at 11:39 AM

    Pretty section of content. I just stumbled upon your weblog
    and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Any way I’ll be subscribing to your augment and even I achievement you access consistently rapidly.

Leave a Reply

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

Hello world in c solution
Playing with characters problem solution
sum and difference of two numbers problem solution
functions in c problem solution
pointers in c problem solution
Conditional statements in c problem solution
For loop in c solution
Sum of Digits of a five-digit number problem solution
Bitwise operators problem solution
Printing pattern using loops problem solution
1D Arrays in c problem solution
Array Reversal problem solution
Printing Tokens problem solution
Digit Frequency problem solution
Dynamic Array in c problem solution
Calculate the Nth term problem solution
Students Marks sum problem solution
Sorting Array of strings problem solution
Permutations of strings problem solution
Variadic functions in c problem solution
Querying the documents problem solution
Boxes through a tunnel problem solution
Small Triangles, Large Triangles problem solution
post-transition problem solution
Structuring the document problem solution

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes