2
LAB EXERCISES
3. Create a program that allow user to enter the numbers and this programs will prints the
numbers vertically.
4. Create a program that allow user to enter 10 numbers and this program will prints the
first and the last one on one line, the second and the ninth on the next line, the third
and the seventh on the next line and so forth.
ANSWER
Question 1:
source code
/*
Author : xxx
Description: Lab 1.1 & 1.2
Date : 3 January 2008
*/
#include <iostream.h>
#include <cstdlib>
void main ()
{//open main
cout<<"*"<<endl;
cout<<"**"<<endl;
cout<<"***"<<endl;
cout<<"****"<<endl<<endl;
system ("pause");
}//end main
console application
Question 2:
source code
/*
Author : xxx
Description: Lab 1.1 & 1.2
Date : 3 January 2008
*/
#include <iostream.h>
#include <cstdlib>
void main ()
{//open main
system ("pause");
}//end main
console application
Question 3:
source code
/*
Author : xxx
Description: Lab 1.1 & 1.2
Date : 3 January 2008
*/
#include <iostream.h>
#include <cstdlib>
void main ()
{//open main
float num1,num2,num3,num4,num5;
//get input
cout<<"\nEnter Number:";
cin>>num1;
cout<<"\nEnter Number:";
cin>>num2;
cout<<"\nEnter Number:";
cin>>num3;
cout<<"\nEnter Number:";
cin>>num4;
cout<<"\nEnter Number:";
cin>>num5;
//print output
cout<<"\n....................."<<endl<<endl;
cout<<num1<<endl;
cout<<num2<<endl;
cout<<num3<<endl;
cout<<num4<<endl;
cout<<num5<<endl<<endl;
system ("pause");
}//end main
console application
Question 4:
source code
/*
Author : xxx
Description: Lab 1.1 & 1.2
Date : 3 January 2008
*/
#include <iostream.h>
#include <cstdlib>
void main()
{//open main
float num1,num2,num3,num4,num5,num6,num7,num8,num9,num10;
//get input
cout<<"\nEnter Number:";
cin>>num1;
cout<<"\nEnter Number:";
cin>>num2;
cout<<"\nEnter Number:";
cin>>num3;
cout<<"\nEnter Number:";
cin>>num4;
cout<<"\nEnter Number:";
cin>>num5;
cout<<"\nEnter Number:";
cin>>num6;
cout<<"\nEnter Number:";
cin>>num7;
cout<<"\nEnter Number:";
cin>>num8;
cout<<"\nEnter Number:";
cin>>num9;
cout<<"\nEnter Number:";
cin>>num10;
//show output
cout<<"\n..........................."<<endl<<endl;
cout<<num1<<"\t"<<num10<<endl;
cout<<num2<<"\t"<<num9<<endl;
cout<<num3<<"\t"<<num8<<endl;
cout<<num4<<"\t"<<num7<<endl;
cout<<num5<<"\t"<<num6<<endl<<endl;
system ("pause");
}//end main
console application