# Write a program to read a four digit integer and print the sum of its digits.Write a program that reads a floating point number and then displays the right-most digit of the integral part of the number.

#### sarathi trichy Profile Answers by sarathi trichy

• Nov 29th, 2007

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z,k=0;
clrscr();
printf("enter the number");
scanf("%d",&x);
while(x>0)
{
y=x%10;
k=k+y;
x=x/10;
}
printf("%d",k);

getch();
}

#### Susil Kumar Profile Answers by Susil Kumar

• Jan 5th, 2008

Program that reads a floating poing number and then displays the right-most digit of the integral part of the number

Steps to do it:

2. Convert it to a string
3. Consider the string having array of characters
4. Store the characters in an array of characters
5. Print the array
6. Stop

#include<stdio.h>
main(){
float digit;
char c[10],r_digit[10];
printf("nEnter the floating number:");
scanf("%f",&digit);
sprintf(c,"%s",digit); /* Floating value is stored as a string in c*/

len=strlen(c)-1;

i=0;
j=0;
while(i<len){
if(c[i]=='.'){
break;
}
i++;
}

i++;

while(i<len){

r_digit[j]=c[i];

j++;

i++;

}
r_digit[i]='';

printf("nThe right-most digit from the given integer:%s",r_digit);

}

• Apr 18th, 2008

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,r,sum=0;
cout<<"Enter any four digit number";
cin>>n;
while(n>0)
{
r=n%10;//To get remainder
sum=sum+r;
n=n/10;//To get coefficient
}
cout<<"The sum of the given four digt number is:"<<sum;
getch();
}

• Apr 17th, 2012

```Code#include<stdio.h>
#include<conio.h>
main()
{
float f;
int s,r,k=1;
printf("Enter the number:=>");
scanf("%f",&f);
s=f/1;
while(k==1)
{
r=s%10;
printf("%d
",r);
k++;
}
return 0;
} ```

#### karuna gaur

• Apr 15th, 2013

456 sum is 15

```Codeint sumDigits(int n) {
int sum = 0;

while( n > 0 ) {
sum += (n % 10); // add last digit of n to sum
n /= 10; // divide n by 10 to "chop off" the last digit
}

return sum;

getch();
}```

#### gaurav kumar jaiswal

• Aug 31st, 2014

write a c++ program to the sum and product of digits of an integers