标签:
项目1.数组的分离
#include <iostream> using namespace std; int main() { int a[10],i,j,n; cout<<"请输入十个数:"<<"\n"; for(i=0; i<10; i++) { cin>>a[i]; } cout<<"十个数中偶数有:"; for(j=0; j<10; j++) { if(a[j]%2==0) cout<<a[j]<<","; } cout<<"\n"; cout<<"十个数中奇数有:"; for(n=0; n<10; n++) { if(a[n]%2!=0) cout<<a[n]<<","; } return 0; }项目2.数组的选择
<pre name="code" class="cpp">#include <iostream> using namespace std; int main() { int a[10],b[10],i,j,n=0; cout<<"请输入10个数:"<<"\n"; for(i=0; i<10; i++) cin>>a[i]; for(i=0; i<10; i++) { for(j=0; j<10; j++) { if(a[i]==a[j]&&i!=j)break; if(j==9) { b[n]=a[i]; n++; } } } cout<<"不重复的数组B为:"; for(i=0; i<n; i++) cout<<b[i]<<"\t"; cout<<endl; return 0; }
#include<iostream> #include<cstdio> using namespace std; int main() { char str[50]; int i=0,j=0,n=0,k=0,w=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') { if(str[i]>='0'&&str[i]<='9') n++; else if(str[i]>='A'&&str[i]<='Z') j++; else if(str[i]>='a'&&str[i]<='z') k++; else w++; i++; } cout<<"其中的数字个数是: "<<n<<endl; cout<<"其中的大写字母个数是: "<<j<<endl; cout<<"其中的小写之母个数是: "<<k<<endl; cout<<"其中的其他字符个数是: "<<n<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/shengcongcong/article/details/51360155