Smallest and
Largest Number from List of 10 numbers program in C++
Smallest
and largest number from list a of 10 numbers enter by user. Yes you are at
right place if you are looking for such program in C++ language. To find out
which number is smallest or which one is the greatest from the two or three
numbers is an easy task but when we have to deal with the more numbers. The
complete phenomenon has been changed and we have to use the totally different
logic.
Logic
We
will use a while loop and get the ten values one by one. Also we have inserted
two more conditional statements to find the smallest and other to find the
largest number. We have declared two variables min and max for minimum and
maximum value. We have assigned minimum and maximum to a value on the
respective condition to be true.
Code
#include<iostream>
using
namespace std;
int
main()
{
int x=1,y,total=0,number,max,min=1000;
while(x<=10)
{
cout<<" ENTER NUMBER \n ";
cin>>number;
if(number>max)
max=number;
else if(number<min)
min=number;
x++;
}
cout<<" Largest = "<<max<<endl;
cout<<" Smallest
= "<<min<<endl;
return 0;
}
Output
Now
here is the running program snap shot.
Sum of
Square of numbers from 1 to 10 Program in C++
Now
this program will display the squares of numbers from 1 to 10 and the sum of
these squares. This C++ program is very small and simple and its logic is also
easy to understand. We will take a while loop run it from 1 to 10. Each time it
runs it will find the square of a number and display it on screen also it add
this sum to a variable total. When while loop will terminate, we will print the
value of total outside while loop, which will be the sum of square of numbers.
That’s it.
Code
#include<iostream>
using
namespace std;
int
main()
{
int x=1,y,total=0;
while(x<=10)
{
y=x*x;
cout<<y<<endl;
total+=y;
x++;
}
cout<<" total = "<<total<<endl;
return 0;
}
Output
Now
here is the running program output.
Thank
you for learning the code from here if any type of bug is iterating you to run
your code comment us we will try our best to solve your error.
Post a Comment
Feel Free to Comment Us