C + + Brush question two

Source: Internet
Author: User

(i) there is a fractional sequence: 2/1 3/2 5/3 8/5 13/8 21/13 ... The sum of the first n items of this sequence is calculated, and two decimal places are reserved. #include <iostream> #include <iomanip>using namespace Std;int main () {    int i,n;    Double m=2.0,n=1.0,s,sum=0;    cin>>n;    for (i=0;i<n;i++)    {        sum=m/n+sum;        S=m+n;        n=m;        m=s;    }    Cout<<setiosflags (ios::fixed) <<setprecision (2) <<sum<<endl;    return 0;}
(ii) Write a function that connects two strings 123     abc123abc#include <iostream> #include <string>using namespace Std;int main () {    string A, B;    int i;    cin>>a>>b;    cout<<a;    for (i=0;a[i]!= ' n '; i++);    cout<<b;    return 0;}

(c) Write a function, enter a four-digit number, which requires the output of these four numeric characters, but each of the two digits between the spaces. If you enter 1990, you should output "1 9 9 0". #include <iostream>using namespace std;void output (int num,int n); int main () {    int num,n=4;    cin>>num;    Output (num,n);    return 0;} void output (int num,int n) {    int a[n],i=1;    while (num>0)    {        a[i]=num%10;        NUM=NUM/10;        i++;    }    for (i=n; i>1; i--)        cout<<a[i]<< "";    Cout<<a[1]<<endl;}

(d) Write a function, copy the vowel letters from two strings to another string, and then output. #include <iostream> #include <string>using namespace Std;int main () {    string a B;    int i;    cin>>a>>b;    for (i=0; a[i]!= '; i++)    {        if (a[i]== ' A ' | | a[i]== ' E ' | | a[i]== ' I ' | | a[i]== ' O ' | | a[i]== ' u ')            cout<<a[i];    }    for (i=0; b[i]!= '; i++)    {        if (b[i]== ' A ' | | b[i]== ' E ' | | b[i]== ' I ' | | b[i]== ' O ' | | b[i]== ' u ')            cout<<b[i];    }    return 0;}

(v) Set Circle radius r, cylindrical high h for circular long C1, Circle area sa, sphere surface area sb, sphere Volume VA, cylindrical volume VB. Input data with scanf, output calculation results, the output requires text description, take the decimal point after two digits. Please compile the program. Pi=3.14#include <iostream> #include <iomanip>using namespace Std;int main () {    float r,h;    Double Pi=3.14,c1,sa,sb,va,vb;    cin>>r>>h;    C1=pi*2*r;    Sa=pi*r*r;    Sb=4*pi*r*r;    VA=PI*R*R*R*4/3;    vb=pi*r*r*h-0.005;    Cout<<setiosflags (ios::fixed) <<setprecision (2);    cout<< "c1=" <<C1<<endl;    cout<< "Sa=" <<Sa<<endl;    cout<< "sb=" <<Sb<<endl;    cout<< "Va=" <<Va<<endl;    cout<< "vb=" <<Vb<<endl;    return 0;}

(vi) Write a function that causes the input string to be stored in reverse order, and enter the output back-order string in the main function. #include <iostream> #include <string>using namespace Std;int main () {    string A;    cin>>a;    int i,n;    for (i=0;a[i]!= ' n '; i++)    {        n=i;    }    for (i=n;i>=0;i--)    {        cout<<a[i];    }    return 0;}

Experience: The accumulation of 1.1 points per day is a testament to progress!! Come on!

C + + Brush question two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.