0% found this document useful (0 votes)
20 views

C++ Group Assignment

Uploaded by

blenaqua57js
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

C++ Group Assignment

Uploaded by

blenaqua57js
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Group10

Members ID

Melat Mekonen........1405385
Blen Bizuayehu........1405386
Bisrat Teshome........1405387
1. Write a Basic program to evaluate the following series.

i) 1/1+1/3+1/5+1/7+......+1/n
#include<iostream>
using namespace std;

int main()
{
double n,j,i,sum=0.0;

cout<<"enter a number";
cin>>n;
for(i=1;i<=n;i++)
{
j=2*i-1;
sum=sum+1/j;
}
cout<<sum;
return 0;
}
(ii) 1+32+52+ . . . +n2

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,sum=0;
cout<<"Enter a number: ";
cin>>n;
for(int i=1;i<=n;i=i+2)
{
pow(i,2);
sum=sum+pow(i,2);
}
cout<<sum;
return 0;

4. Write a program in C++ to general a Fibonacci series of ‘n’ numbers,


Hint Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144… N

#include <iostream>
using namespace std;
int main()
{
int n, n1= 0, n2 = 1, nextTerm = 0;
cout << "Enter the number of terms: ";
cin >> n;
for (int i = 1; i <= n; ++i)
{ // Prints the first two terms.
if(i == 1)
{ cout << n1<< ", ";
continue;

if(i == 2)
{ cout << n2 << ", ";
continue;
}
nextTerm = n1+ n2;
n1=n2;
n2 = nextTerm;
cout << nextTerm << ", ";
}
return 0;
}

7. Write C++ program that perform scientific calculator using function

#include<iostream>

#include<math.h>

#include <conio.h>

char op;

using namespace std;

void sum()

int sum = 0;

int n;

int numberitems;

cout << "Enter number of items: \n";

cin >> numberitems;


for(int i=0;i<numberitems;i++)

cout<< "Enter number "<<i<<":\n\n" ;

cin>>n;

sum+=n;

cout<<"sum is: "<< sum<<endl<<endl;

void diff()

int diff;

int n1,n2;

cout<<"enter two numbers to find their difference:\n\n";

cout<<"enter first number:";

cin>>n1;

cout<<"\nenter second number:";

cin>>n2;

diff=n1-n2;

cout<<"\ndifference is:"<<diff<<endl<<endl;

void pro()

int pro=1;

int n;

int numberitems;

cout<<"enter number of items:\n";

cin>>numberitems;

for(int i=0;i<=numberitems;i++)

cout<<"\nenter item "<<i<<":";


cin>>n;

pro*=n;

cout<<"product is:"<<pro<<endl<<endl;

void div()

int div;

int n1;

int n2;

cout<<"enter 2 numbers to find their quotient\n\n";

cout<<"enter numerator:";

cin>>n1;

cout<<"\nenter denominator:";

cin>>n2;

div=n1/n2;

cout<<"\nquotient is:"<<div<<endl<<endl;

void power()

long int p;

int res=1,n;

cout<<"enter number:";

cin>>n;

cout<<"\nenter power:";

cin>>p;

for(int i=1;i<=p;i++)

{
res=n*res;

cout<<n<<"\n power "<<p<<" is :"<<res<<endl;

void sq()

float s;

int n;

cout<<"enter number to find its square root:";

cin>>n;

s=sqrt(n);

cout<<"\nsquare root of "<<n<<" is :"<<s<<endl;

void modulo()

int l,m,t;

cout<<"enter numerator :";

cin>>l;

cout<<"enter denominator :";

cin>>t;

t=l%t;

cout <<"\n remainder equals :"<<t;

int main()

{ do

cout<<"***which operation you want to perform***\n";

cout<<"press 0 for exit\n";

cout<<"press 1 for addition \n";


cout<<"press 2 for subtraction\n";

cout<<"press 3 for multiplication\n";

cout<<"press 4 for division\n";

cout<<"press 5 for power calculation\n";

cout<<"press 6 for square root \n";

cout<<"press 7 for remainder \n";

cout<<"press option:";

cin>>op;

switch(op)

case '1':

sum();

break;

case '2':

diff();

break;

case '3':

pro();

break;

case '4':

div();

break;

case '5':

power();

break;

case '6':

sq();

break;

case '7':

modulo();

break;
exit(0);

default:

cout<<"invalid input" ;

while(op!='0');

getch();

You might also like