Professional Documents
Culture Documents
2 ND PL Exercise
2 ND PL Exercise
Project
In
Programming
Languages
S.Y. 2015-2016
Submitted by:
James Q. Monsanto
BSCS-IT-2C
Submitted to:
Prof. Gina Clemente
Output:
Output:
}while(n<=10)
;
int k;
cin>>k;
getch ();
return 0;
}
Output:
14. Fibonacci
#include<iostream.h>
#include<conio.h>
class fib
{
public:
int a,b,c;
void generator(int);
};
void fib::generator(int n)
{
a=1,b=1;
cout<<a<<" "<<b;
for(int i=1;i<=n-2;i++)
{
c=a+b;
cout<<" "<<c;
a=b;
b=c;
}
}
void main()
{
clrscr();
int n;
cout<<"Enter number of terms you need in the series: ";
cin>>n;
fib ob;
ob.generator(n);
getch();
}
Output:
Output:
<<"\n
Candidate\n";
cin>>choice;
switch(choice){
case 'A':
case 'a':
ca++;
break;
case 'B':
case 'b':
cb++;
break;
case 'C':
case 'c':
cc++;
break;}
}
else if (choice2=='R'){
cout<<"\t Presidential Elections\n\n";
cout<<"Candidates:"<<"\t
Results:"<<"\n\n";
<<ca<<"\n";
<<cb<<"\n";
Output:
Output:
18. Number-Asterisk
A.
#include<iostream.h>
#include<conio.h>
void main(){
int i,j;
Output:
clrscr();
for(i=1 ; i<=5 ; i++){
for(j=0 ; j<=9 ; j++){
cout<<j;}
cout<<endl;}
getch();
}
B.
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1; i<=6; i++){
for(j=1; j<i; j++){
cout<<"*";
}
cout<<"\n";
}
getch();
}
C.
Output:
#include <iostream.h>
#include<conio.h>
main(){
int i,j;
clrscr();
for(i=5;i>=1;--i){
for(j=1;j<=i;++j){
cout<<j<<" ";
}
cout<<"\n";
}
getch ():
return 0;
}
cout<<endl;
}
Output:
getch ();
return 0;
}
Output:
MENU\n";
case '+':
sum = num1+num2;
cout<<"\nThe answer is:"<<sum<<endl;
break;
case '-':
difference = num1-num2;
cout<<"\nThe answer is: "<<difference<<endl;
break;
case '*':
product = num1*num2;
cout<<"\nThe answer is: "<<product<<endl;
break;
case '/':
quotient = num1/num2;
cout<<"\nThe answer is: "<<quotient<<endl;
}
getch ();
return 0;
}
Output: