Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

Showing posts with label Maths. Show all posts
Showing posts with label Maths. Show all posts

Telephone Digits The following program reads the letter codes A to Z and prints the corresponding telephone digit. This program uses a sentinel-controlled while loop. To stop the program, the user is prompted for the sentinel, which is #. This is also an example of a nested control structure, in which if. . .else, switch, and the while loop are nested.

//**********************************************************
// Program: Telephone Digits
// This is an example of a sentinel-controlled loop. This
// program converts uppercase letters to their corresponding
// telephone digits.
//**********************************************************

#include <iostream>
using namespace std;
int main()
{
char letter; //Line 1
cout << "Program to convert uppercase "
<< "letters to their corresponding "
<< "telephone digits." << endl; //Line 2
cout << "To stop the program enter #."
<< endl; //Line 3
cout << "Enter a letter: "; //Line 4
cin >> letter; //Line 5
cout << endl; //Line 6
while (letter != '#') //Line 7
{
cout << "The letter you entered is: "
<< letter << endl; //Line 8
cout << "The corresponding telephone "
<< "digit is: "; //Line 9
if (letter >= 'A' && letter <= 'Z') //Line 10
switch (letter) //Line 11
{
case 'A':
case 'B':
case 'C':
cout << 2 <<endl; //Line 12
break; //Line 13
case 'D':
case 'E':
case 'F':
cout << 3 << endl; //Line 14
break; //Line 15
case 'G':
case 'H':
case 'I':
cout << 4 << endl; //Line 16
break; //Line 17
case 'J':
case 'K':
case 'L':
cout << 5 << endl; //Line 18
break; //Line 19
case 'M':
case 'N':
case 'O':
cout << 6 << endl; //Line 20
break; //Line 21
case 'P':
case 'Q':
case 'R':
case 'S':
cout << 7 << endl; //Line 22
break; //Line 23
case 'T':
case 'U':
case 'V':
cout << 8 << endl; //Line 24
break; //Line 25
case 'W':
case 'X':
case 'Y':
case 'Z':
cout << 9 << endl; //Line 26
}
else //Line 27
cout << "Invalid input." << endl; //Line 28
cout << "\nEnter another uppercase "
<< "letter to find its "
<< "corresponding telephone digit."
<< endl; //Line 29
cout << "To stop the program enter #."
<< endl; //Line 30
cout << "Enter a letter: "; //Line 31
cin >> letter; //Line 32
cout << endl; //Line 33
}//end while
return 0;
}

Circumference and Center of Circle

#include<iostream>
#include<math.h>
float circumference(float,float);
float radius(float,float);
float distance(float,float,float,float);
float area(float,float);
const double p=3.1416;
using namespace std;
void main()
{
float x1,x2,y1,y2;
cout<<"Enter first points of circle:\n";
cin>>x1>>x2;
cout<<"Enter second points of circle:\n";
cin>>y1>>y2;
cout<<"distance of circle is:"<<distance(x1,x2,y1,y2);
cout<<"radius of circle is:"<<radius(x1,x2);
cout<<"circumference of circle is:"<<circumference(x1,x2);
cout<<"area of circle is :"<<area(x1,x2);

}
float distance(float x1,float x2,float y1,float y2)
{
float ans;
float p1,p2;
p1=x2-x1;
p2=y2-y1;

p1=pow(p1,2);
p2=pow(p2,2);

ans=p1+p2;
return sqrt(ans);
}
float radius(float x1,float x2)
{
//using formula [(x-h)^2+(y-k)^2]=r^2
float h,k;
float ans;
float p1,p2;
cout<<"Enter center of circle:";
cin>>h,k;
p1=x1-h;
p2=x2-h;

p1=pow(p1,2);
p2=pow(p2,2);

ans=p1+p2;
return sqrt(ans);

}
float circumference(float x1,float x2)
{
float r=radius(x1,x2);
float ans=2*p*r;
cout<<ans;
return ans;
}
float area(float x1,float x2)
{
return pow((p*(radius(x1,x2))),2);
}

C++ code for Perfect numbers

#include<iostream>
using namespace std;
void list(int&, int&);
void main()
{
int num=2;
int ans=0;
cout<<"Complete list of Perfect numbers:\n";
for(int num=0;num<10000;num++)
{
list(num,ans);
}
}
void list(int& num,int & ans)
{
for(int i=1;i<num;i++)
{
if(num%i==0)
{
ans=ans+i;
}
}
if(ans==num)
{
for(int i=1;i<ans;i++)
{
if(ans%i==0)
cout<<i<<" ";
}
cout<<ans<<"\n";
}
ans=0;
}

C++ Code to find Factorial using Recurtion

#include<iostream>
using namespace std;

void Fac(int n, int &ans) //& use to get address
{
ans*=n; // is ans=ans*n;
if(n>1)
Fac(n-1, ans); // 'ans' passed by reference
}
int main()
{
int numb = 0;
int ans = 1;
cout<<"Enter number: ";
cin>>numb; //Getting number
Fac(numb, ans);
cout<<ans<<"\n";
cout<<endl;
return 0;
}

// For any query type it in comment or chat with any online Admin