标签:
项目5:求和<pre name="code" class="cpp">#include<iostream> using namespace std; int main() { double sum1=0,sum2=0; int a[10]; cout<<"请输入十个数"<<endl; for(int i=0;i<10;i++) { cin>>a[i]; if(a[i]>0) sum1=sum1+a[i]; if(a[i]<0) sum2=sum2+a[i]; } cout<<"正数之和为"<<sum1<<endl; cout<<"负数之和为"<<sum2<<endl; return 0; }
项目4:字符串
<pre name="code" class="cpp">#include<iostream> #include<cstdio> using namespace std; int main() { char str[50]; int i=0,n1=0,n2=0,n3=0,n4=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') { if(str[i]>='0'&&str[i]<='9') n1++; else if(str[i]>='A'&&str[i]<='Z') n2++; else if(str[i]>='a'&&str[i]<='z') n3++; else n4++; i++; } cout<<"其中的数字个数是: "<<n1<<"大写字母个数是:"<<n2<<"小写字母的个数是:"<<n3<<"字符个数是:"<<n4<<endl; return 0; }
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;">项目2:数组选择</span>
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px;"></span><pre name="code" class="cpp">#include<iostream> using namespace std; int main() { int A[10],B[10],i,j,flag,k=0; cout<<"请输入10个数"<<endl; for(i=0;i<10;i++) cin>>A[i]; for(i=0;i<10;i++) { for(j=0;j<10;j++) { flag=0; if(i==j) j++; if(A[i]==A[j]) {flag=1; break; } } if(flag!=1) { B[k]=A[i];k++; } } cout<<"B{"; for(i=0;i<k;i++) cout<<B[i]<<","; cout<<"}"<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/kunyihuang/article/details/51347491