write a program to accept a number and print the average of its digits
Answers
Answer:
- #inculde<iostream.h>
- #include<conio.h>
- void main()
- cout<<"What's the Total no. of number"
- cin>>avg_1
- if (avg_1 = 2):
- cout<<"Enter First Number"
- cin>>no_1
- cout<<"Enter Second Number"
- cin>>no_2
- outcome = 1+2
- final_outcome = outcome/2
- print<<"Average of ", no_1, " , ", no_2, " is ", final_outcome
- else:
- cout<<"Function Currently Unavailable "
- getch()
Explanation:
We have written the program in c++. I can write in python and Javascript too if you want. In Program, I have asked what's the total number of which you want to find out the average and then, after getting the input. I have used conditional statement if-else. You can use if-elif-else condition too if you want. When you users input that he wanted to find out average of 2 numbers then, I am awared now I have to divide the sum of 2 numbers by 2 as per formulae of average. If you want to add either 3 or 4 or any other number of total number then, you can go for it by using if-elif-else condition. After Finding average I have printed out the result. If user enters any number except 2 then, it will print the else statement. Same Way, You can go ahead for Your Program.