项目1:数组分离
一、问题及代码
#include<iostream>
using namespace std;
int main()
{
int a[10],b[10],c[10],i,j=0,k=0;
cout<<"请输入十个数:"<<endl;
for(i=0;i<10;i++)
{
cin>>a[i];
if (a[i]%2==0)
b[j]=a[i];
j++;
if(a[i]%2!=0)
c[k]=a[i];
k++;
}
cout<<"偶数: "<<endl;
for(i=0;i<j;i++)
cout<<b[i]<<" ";
cout<<endl;
cout<<"奇数: "<<endl;
for(i=0;i<k;i++)
cout<<c[i]<<" ";
cout<<endl;
return 0;
项目4:字符串
一、问题及代码
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char str[10];
int i=0,n=0,upper=0,lower=0,other=0;
cout<<"输入10个字符:"<<endl;
gets(str);
while(str[i]!='\0')
{
if(str[i]>='0'&&str[i]<='9')
n++;
else if(str[i]>='A'&&str[i]<='Z')
upper++;
else if(str[i]>='a'&&str[i]<='z')
lower++;
else
other++;
}
cout<<"其中的数字个数是: "<<n<<endl;
cout<<"其中的大写字母个数是: "<<upper<<endl;
cout<<"其中的小写字母个数是: "<<lower<<endl;
cout<<"其中的其他字符个数是: "<<other<<endl;
return 0;
}