Skip to main content

How to Find the Sum of Digits of a Number without loop in c programming

C Program to Find Sum of Digits of a Number without loop:-

 In this program, we will calculate the sum of the number inserted by the user or in an inserted integer. The program is taken as an input and stored in the variable number, denoted as no. Initially, the sum of the variable is zero, and then it is divided by 10 to obtain the result or output.

  

ALGORITHMS:-

Step 1: Start 

Step 2: Ask the user to insert an integer as an input. 

Step 3Divide the integer by 10 in order to obtain the quotient and remainder. 

Step 4: Increase the new variable with the remainder received in the above step.

Step 5: Repeat the above steps with the quotient till the value of the quotient becomes zero. 

Step 6Printf the output or sum.

Step 7: Stop.

CODE: - 

#include<stdio.h>

int main()
{
    int n,d1,d2,d3,d4,d5,sum;
    printf("enter any num");
    scanf("%d",&n);
    d1=n%10;
    n=n/10;
    d2=n%10;
    n=n/10;
    d3=n%10;
    n=n/10;
    d4=n%10;
    n=n/10;
    d5=n%10;
    sum= d1+d2+d3+d4+d5;
    printf("%d\n",sum);
    return 0;
}





OUTPUT:-








FOLLOW THIS WEBPAGE FOR MORE NEW PROGRAMS AND CODING SOLUTIONS.

Comments

Popular posts from this blog

Write a C program to find number is Abundant number or not

  Write a C program to find the number is an Abundant number or not:- In this program to find a number is an Abundant number or not. A number n is said to be an Abundant Number to follow these condition the sum of its proper di visors is greater than the number itself. And the difference between these two values is called abundance. Ex:-  Abundant number  12 having a proper divisor is 1,2,3,4,6 the sum of these factors is 16 it is greater than 12 so it is an Abundant number. Some other abundant numbers     18, 20, 24, 30, 36, 66, 70, 72, 78, 80, 84, 88, 90, 96, 100, 102, 104, 108, 112, 114, 120.. ALGORITHMS:- Step 1 - Enter the number, to find the Abundant number. Step 2 - Initialize the loop with c=1 to c<=number and follow the following calculation      (i) check if whether the number is divisible with c and c got a result zero.      (ii) now sum=sum+c, add a digit into a sum and store it in the sum. Step 3 . then the...

A simple way to Understand how you get attack from Phishing (Emails, Messaging Apps etc.)

  A simple way to Understand how you get attacks from Phishing (Emails, Messaging Apps etc ) What is Phishing? Phishing is the fraudulent attempt to obtain sensitive information or data, such as usernames, passwords, and credit card details, by disguising oneself as a trustworthy entity in electronic communication such as (Email, SMS, Text messages, Mobile app messages, and social media posts.) So how does phishing attacks work- A malicious link will be sent, once clicked, It begins the process to Steal data, financial card information, login credentials, and also infect your device, phones with malware(Virus) when you download the attached document. Phishing links don’t just come in emails alone. several malicious links that lead to stolen data and infected devices can be found in SMS text messages, Mobile app messages, Social media posts . How I received these compromised messages.- The phishing emails and text may usually look like a message from a company you know or trust. The...

Data Structure Multiple Choice Questions and Answers

  Data Structure Multiple Choice Questions and Answers Our 1000+ multiple choice questions and answers (MCQs) on "Data Structure - I" (along with 1000+ MCQs on "Data Structure - II (Algorithms)") focus on all areas of Data Structure covering 200+ topics. One can read MCQs on Data Structure - II (Algorithms)                 Array and Array Operations This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Array and Array Operations”. 1. Which of these best describes an array? a) A data structure that shows a hierarchical behavior b) Container of objects of similar types c) Arrays are immutable once initialised d) Array is not a data structure View Answer Answer: b Explanation: Array contains elements only of the same type. 2. How do you initialize an array in C? a) int arr[3] = (1,2,3); b) int arr(3) = {1,2,3}; c) int arr[3] = {1,2,3}; d) int arr(3) = (1,2,3); View Answer Answer: c Explanation: This is the syntax ...