The following function will sum the digits in any positive number.
unsigned int sum_digits(unsigned int num, unsigned int base=10)
{
sum=0;
if(base>1) // base must be 2 or higher
{
while(num)
{
sum+=num%base; // add least significant digit to sum
num/=base; // shift right by base
}
}
return(sum);
}
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
To write a program that inputs a number and displays the digits absent in it, you can follow these steps: Convert the input number into a set of its digits. Create a set of all possible digits (0-9). Subtract the set of digits from the complete set to find the missing ones. Display the missing digits. Here’s a simple example in Python: number = input("Enter a number: ") present_digits = set(number) all_digits = set('0123456789') missing_digits = all_digits - present_digits print("Missing digits:", ''.join(missing_digits))
5
program to extract a given word from a file
write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)
One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.
You write the number and then follow it with the digits in reverse order.
5
An Armstrong number (or narcissistic number) for a given number of digits is a number that is equal to the sum of its own digits raised to the power of the number of digits. Here’s a simple Visual Basic 10 program that checks for Armstrong numbers: Module ArmstrongNumber Sub Main() Dim num As Integer Dim sum As Integer = 0 Console.Write("Enter a number: ") num = Convert.ToInt32(Console.ReadLine()) Dim temp As Integer = num Dim digits As Integer = num.ToString().Length While temp > 0 Dim digit As Integer = temp Mod 10 sum += Math.Pow(digit, digits) temp \= 10 End While If sum = num Then Console.WriteLine(num & " is an Armstrong number.") Else Console.WriteLine(num & " is not an Armstrong number.") End If End Sub End Module This program takes a number as input, calculates the sum of its digits raised to the power of the number of digits, and checks if the sum equals the original number.
THIS IS ONLY FOR UPTO A FIVE DIGIT NO. BY ROHAN ARORA#include#includevoid main(){int a,n,s,sum=0;clrscr();printf("Enter the number between 1 to 5 digits\n");scanf("%d",&a);while(a!=0){n=a%10;sum=sum+n;a=a/10;}printf("The sum of digits of the given numberis %d",sum);getch();}
Yes, do write, or if you're too lazy to your homework, use google.
All four of the digits given are significant digits.
8086 assembly language program to check wether given number is perfect or not
Million is the name given to a number with 7 digits in front of the decimal place. In order to write out any number take the number you are given and and move the decimal place to the right until you have 7 digits in front of the decimal. add zeros to the end until it has 7 digits in front of the decimal place. So 2.25 million would be 2,250,000.
36
03458
The number is 36.