C++第5次实验作业

来源:互联网 发布:mac pro垃圾桶 玩游戏 编辑:程序博客网 时间:2024/06/15 01:09

一、问题及代码

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
 char str[50];
 int i=0,j=0,r=0,n=0,m=0,k=0;
 cout<<"输入字符串:";
 gets(str);
 while(str[i]!='\0')
 {
  if(str[i]>='0'&&str[i]<='9')n++;
  i++;
 }
 while(str[j]!='\0')
 {
  if(str[j]>='a'&&str[i]<='z')m++;
  j++;
 }  
 while(str[r]!='\0')
 {
  if(str[r]>='A'&&str[r]<='Z')
   k++;
  r++;
 }
 cout<<"其中的数字个数是:"<<n<<endl;
 cout<<"其中的小写字母个数是:"<<m<<endl;  
 cout<<"其中的大写字母个数是:"<<k<<endl;
 return 0;
}
二、运行结果:

一、问题及代码

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
 int a[10],i,m=0,n=0;
    for(i=0;i<10;i++)
  cin>>a[i];
 for(i=0;i<10;i++)
  if(a[i]>=0)m+=a[i];
  else n+=a[i];
  cout<<"其中的正数和是:"<<m<<endl;
  cout<<"其中的负数和是:"<<n<<endl;
  return 0;
}

二、运行结果:


0 0
原创粉丝点击