Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
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 June 2025

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.

Solution explained in Video

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

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

Leave a Reply

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

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes