program to find sum of digits for n digit number

looking to find a sum of numbers, do not worry when c4fun is here

Problem?
today what we are going to do?
yes you are right
we are
.......
going to find the sum of a digit , in which we have taken input from the user.
it happens that some basic codes are not coming to our mind but don't worry it all out striking the mind at right time, with many great people this has happened that simple logic is missing and then they are sitting thinking what to do .so this is like practice and practise which is going to tell you that you are perfect ..
so keep learning and coding.
are you facing problem in making simple and basic coding programs don't worry here on our blog every program is available with simple and basic codes you will be glad to find the simple logic and codes  by which you can make the simple and basic codes and can impress any your friend s by telling them you know the coding but remember first try yourself then you should move on to the solution so that you may gain  the confidence and thus it will only help you to gain the boost up .
so today we are going to find the sum of the digits which has been inoputed bytthe user as an input and we ahve storedi t in anuy variables.
To find the sum of digits of a given integer.

below is the step by step logic provided to you, you may go through each step and if you are facing any sort of confusion then you can drop a comment with the doubt, ill be there to resolve the issue

tried my best to give you the basic but simple logic program and thus hope you will be able to do the way you want to implement this.
Solution...
.   ask for integer input .
. Divide it by 10, get its remainder and quotient.
. Increase the new variable with the remainder .
. Repeat the step, with the quotient obtained 
uptill  qoutient becomes zero.
. Print the output.


hope you have gone through the steps of your program what all is needed

try to make logic yourself now, all steps are explained and if you are stuck don't worry below is source code there to help you.

 Code
c4fun brings the  C program to find a sum of digits of a given integer.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,s=0,m;
clrscr();
printf("\n enter number");
scanf("%d",&n);
m=n;
while(m>0)
{
d=m%10;
s=s+d;
m=m/10;
}
printf("sum of %d =%d",n,s);
getch();
}



comment down the result you have obtained and if you find the program a help and think that this might help others also then feel free to s=hare it among your friends and help them also to make programs which they might think are very hard because of the reason that they were known of the code.
remember sharing is caring and if you help others to understand the basic they will always be alike friends a.
it will serve a dual purpose to you as it will help you to understand the program and as well as your friend also so for what you are waiting for t share now and help others  rajporac4fun


an output is shown  and use the different input to find the sum of the numbers, have fun finding the different sum of a number of big lengths .compare them and show to your end

comment on the result you have got and let us see the biggest result you can obtain when you run the code.

keep coding
happy earning...

No comments

thanks for reading and sharing.I hope it would help you!!!!

Powered by Blogger.