RE: 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.
#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);
RE: 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.
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:
1. Read the floating value 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*/
RE: 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.
#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(); }