Sum Of Two Digits in C
Q. Write a C program for Sum of Two Digits.
#include
#include
Void main(){
int a,b,c;
clrscr();
printf("Enter the numbers:");
scanf("%d %d",&a,&b);
c=a+b;
printf("Sum Of Two Digits is: %d ",c);
getch();
}
Q. Write an algorithm to Sum of Two Digits.
1. Start
2. Declare integer variables: `n` (input number), `r` (digit), `sum`, `t` (temporary variable)
3. Initialize `sum` to 0
4. Prompt the user to enter a number and read it into `n`
5. Assign `t = n`
6. While `t` is greater than 0:
a. Extract the last digit: `r = t % 10`
b. Add cube of the digit to sum: `sum = sum + (r * r * r)`
c. Remove the last digit: `t = t / 10` (integer division)
7. If `sum` equals the original number `n` then
a. Print "`n` is an Armstrong number"
8. Else
a. Print "`n` is not an Armstrong number"
9. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com