C + + fifth time job

Source: Internet
Author: User

One, array separation

#include <iostream>  using namespace std;  int main ()  {      cout<< "Please enter 10 numbers" <<endl;      int i=0,j=0,k=0,a[10],b[10],c[10];        for (i=0;i<10;i++) cin>>a[i]; for (i=0;i<10;i++)    {          if (a[i]%2==0)          {              b[j]=a[i];              j + +;          }          else          {              c[k]=a[i];              k++;          }      } cout<< "even array is"; for (i=0;i<j;i++) {cout<<b[i]<< "";} cout<<endl;cout<< "Odd Array is"; for (i=0;i<k;i++) {cout<<c[i]<< "";} Cout<<endl;return 0;}


Second, array selection

#include <iostream>  using namespace std;  int main ()  {cout<< "Please enter 10 numbers:" <<endl;int i=0,j=0,k=0,a[10],b[10],c[10];for (i=0;i<10;i++) cin> >a[i];for (i=0;i<10;i++) {for (j=0;j<10;j++) {if (i==j) continue;if (A[i]==a[j]) {b[i]=a[i];b[j]=a[j];}}} cout<< "Non-repeating number:" <<endl;for (i=0;i<10;i++) {if (A[i]==b[i]) continue;c[k]=a[i];cout<<c[k]< < ""; k++;} Cout<<endl;return 0;}


Three, string

#include <iostream> #include <cstdio>  using namespace std;  int main ()  {char str[50];int i=0,j=0,k=0,m=0,n=0;cout<< "input string:"; gets (str); while (str[i]!= ') {if (Str[i] >= ' 0 ' &&str[i]<= ' 9 ') j++;else if (str[i]>= ' a ' &&str[i]<= ' Z ') k++;else if (str[i]>= ' a ' &&str[i]<= ' z ') M++;else n++;i++;} cout<< "The number of numbers is:" <<j<<endl;cout<< "where the number of uppercase letters is:" <<k<<endl;cout<< " The number of lowercase letters is: "<<m<<endl;cout<<" where the number of other characters is: "<<n<<endl;return 0;}


C + + fifth time job

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.