SPECIAL NUMBER
Write a program to get input from the user and find the number
is special number or not.
A 2-digit number is said to be a special number if the sum of the
sum of its digits and the products of its digits is
equal to the number itself.
For example, 19 is a special number. The digits in 19 are 1 and
9. The sum of the digits is 10 and the product of the
digits is 9.
10+9 = 19.
Comalo
Answers
Answered by
2
Answer:
This is the required C program for the question.
#include <stdio.h>
int main () {
int n,fd,ld,x;
printf("Enter a number - ");
scanf("%d",&n);
fd=n/10;
ld=n%10;
x=fd+ld+fd*ld;
if(n==x)
printf("Special Number.");
else
printf("Not a Special Number.");
return 0;
}
Explanation:
- Line 1: Include the standard input output header file.
- Line 2: Beginning of main() function. (Starting of execution point)
- Line 3: Declares the variable necessary for the program.
- Line 4: Ask the user to enter the number.
- Line 5: Number is taken as input.
- Line 6: Calculates the first digit and store it in variable fd.
- Line 7: Calculates the last digit and store it in variable ld.
- Line 8: Find the product and sum of digits and add them and store the result in x.
- Line 9: Check if number is equal to x.
- Line 10: If true, number is a special number. Display the message.
- Line 11: Else block.
- Line 12: Display the message that the number is not a special number.
- Line 13: returns 0.
- Line 14: Close of main.
See the attachment for output ☑.
Attachments:
Similar questions
Computer Science,
1 month ago
English,
1 month ago
Math,
3 months ago
Math,
3 months ago
Environmental Sciences,
9 months ago