Find Sum of Digits of a Number : C Program

Computer Science » C Program » Find Sum of Digits of a Number

Program :

#include <stdio.h>
 
int main()
{
    long number, digit, sum = 0;
 
    printf("Enter the number :");
    scanf("%ld", &number);
 
    while (number > 0)
    {
        digit = number % 10;
        sum  = sum + digit;
 
        number = number / 10;
    }
 
    printf("nSum of the digits of given number is : %ld", sum);
}

Output :

Enter the number : 2882
Sum of the digits of given number is : 20
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Calculate Sum of 5 Subjects and Find Percentage : C ProgramComputer Science » C Program » Calculate Sum of 5 Subjects and Find Percentage Program : [php]#include<stdio.h> int main() { int s1, s2, s3, s4, s5, sum, total = 500; float percentage; printf("nEnter marks of 5 subjects : "); scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5); sum = s1 + s2 + s3 + s4 + s5; printf("nSum : %d", sum); percentage = (sum * 100) / total; printf("nPercentage : %f", percentage); return (0); }[/php] Output : [php]Enter marks of 5 subjects : 90 70 90 80 70 Sum : 400 Percentage : 80.00[/php]
    Tags: program, sum, find, computer, science, output, programs
  • Find Largest Element in Array : C ProgramComputer Science » C Program » Find Largest Element in Array Program : [php]#include<stdio.h> int main() { int a[30], i, num, largest; printf("nEnter no of elements : "); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as largest largest = a[0]; for (i = 0; i < num; i++) { if (a[i] > largest) { largest = a[i]; } } // Print out the Result printf("nLargest element is : %d", largest); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Largest element is : 50[/php]
    Tags: program, find, computer, science, output, programs
  • Find Sum of Two Float Numbers : C ProgramComputer Science » C Program » Find Sum of Two Float Numbers Program : [php]#include<stdio.h> int main() { float a, b, sum; printf("Enter two numbers : "); scanf("%f %f", &a, &b); sum = a + b; printf("nSum : %.2f", sum); return(0); }[/php] Output : [php]Enter two numbers : 2.2 3.6 Sum : 5.80[/php]
    Tags: program, find, sum, computer, science, output, programs
  • Find the Simple Interest : C ProgramComputer Science » C Program » Find the Simple Interest Program : [php]#include<stdio.h> int main() { int amount, rate, time, si; printf("nEnter Principal Amount : "); scanf("%d", &amount); printf("nEnter Rate of Interest : "); scanf("%d", &rate); printf("nEnter Period of Time : "); scanf("%d", &time); si = (amount * rate * time) / 100; printf("nSimple Interest : %d", si); return(0); }[/php] Output : [php]Enter Principal Amount : 100 Enter Rate of Interest : 5 Enter Period of Time : 2 Simple Interest : 10[/php]
    Tags: program, find, computer, science, output, programs
  • Check Whether a Number is Palindrome or Not : C ProgramComputer Science » C Program » Check Whether a Number is Palindrome or Not  Program : [php]#include <stdio.h> int main() { int n, reversedN = 0, remainder, originalN; printf("nEnter an integer : "); scanf("%d", &n); originalN = n; // reversed integer is stored in reversedN while (n != 0) { remainder = n % 10; reversedN = reversedN * 10 + remainder; n /= 10; } // palindrome if orignalN and reversedN are equal if (originalN == reversedN) printf("n%d is a palindrome.", originalN); else printf("n%d is not a palindrome.", originalN); return 0; }[/php] Output 1: [php]Enter an integer: 101 101 is a palindrome.[/php] Output 2: [php]Enter an integer: 102 102 is not a palindrome.[/php]
    Tags: program, number, output, computer, science, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here