By using this programyou can find average of maximum 50 numbers. c++ code #include <iostream.h> void main() { int A[50],n; float sum=0; cout<<"How many numbers do you wish to enter : "; cin>>n; cout<<"\nEnter numbers : "; for(int i=0;i<n;i++) { cin>>A[i]; sum+=A[i]; } cout<<"\nAverage = "<<sum/n; } OUTPUT - How many numbers do you wish to enter :5 Enter numbers :5 4 8 7 6 Average =6
Posts
If there is any length given in feet and inches then you can use this code to convert it into cm. ex-if length is 3 feet and 8 inches then your fwill be=3.8 c++ code #include <iostream.h> #include <conio.h> void main() { clrscr(); float f; cout<<"Enter height in feet and inches : "; cin>>f; cout<<"\nHeight in cm = "<<f*12*2.54; getch(); } OUTPUT- Enter height in feet and inches : 3.8 Height in cm =115.824
If you want to run this program for more then five no.,then you have to modify A[5] and i<5. C++ code for array of five numbers. #include <iostream.h> void main() { int A[5],n=0,m=0; cout<<"Enter numbers : "; for(int i=0;i<5;i++) { cin>>A[i]; if(A[i]%2==0) n++; else m++; } cout<<"\nNo. of odd numbers = "<<m; cout<<"\nNo. of even numbers = "<<n; } OUTPUT- Enter numbers : 6 2 3 4 5 no. of odd numbers =2 no. of even numbers =3
Absolute value means only how far a number is from zero. or we can say, absolute value of a=|a| c++ code #include <iostream.h> #include <math.h> void main() { int a; cout<<"Enter number : "; cin>>a; cout<<"\nAbsolute value = "<<sqrt(a*a); //OR use - cout<<"\n"<<fabs(a); } OUTPUT- Enter number :-3 Absolute value =3