Download Printing numbers in reverse order 1 Case of 3 numbers Program

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mathematics of radio engineering wikipedia , lookup

Large numbers wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Addition wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Printing numbers in reverse order
1 Case of 3 numbers
Program
#include <iostream.h>
// Example to motivate need for arrays
// Write a program to read in 3 integers, one per line, and to
// write them out in reverse order
int main(void)
{
int x1,x2,x3;
cout<<"Enter whole number 1"<<endl;
cin>>x1;
cout<<"Enter whole number 2"<<endl;
cin>>x2;
cout<<"Enter whole number 3"<<endl;
cin>>x3;
cout<<"Whole number 3 is "<<x3<<endl;
cout<<"Whole number 2 is "<<x2<<endl;
cout<<"Whole number 1 is "<<x1<<endl;
return 0;
}
Input & Output
2 Case of 50 numbers
Program
#include <iostream.h>
// Example to motivate need for arrays
// Write a program to read in 50 integers, one per line, and to
// write them out in reverse order
//
int main(void)
{
int x[50],i;
for(i=0;i<50;i++)
{
cout<<"Enter whole number "<<i+1<<endl;
cin>>x[i];
}
//
for(i=49;i>-1;i--)
{
cout<<"Whole number "<<i+1<<" is "<<x[i]<<endl;
}
return 0;
}
Input & Output