c++数组习题(1)

c++数组习题(1),第1张

1)从键盘上输入一个字符串,假定该字符串的长度不超过50,
试统计出该串中十进制数字字符的个数并输出
#include

int main()
{
int a[51];
cin>>a;
for(int i=0;i<=50;i++)
{if(a[i]<+'9' &&a[i]>+'0')k++;}
cout< }

2)从键盘上输入一个字符串,假定该字符串的长度不超过50,
试统计出该串中每一种十进制数字字符的个数并输出

#include
#include


using namespace std;

int main()
{

    char str[51];
    int v1, v2, v3, v4, v5, v6, v7, v8, v9, v0;
    v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = v0 = 0;
    int k = 0;
    cin >> str;
    for (int i = 0; i <= 50; i++)
    {

        if ((str[i]) == '0') v0++, k++;
        if (str[i] =='1') v1++, k++;
        if (str[i] == '2') v2++, k++;
        if (str[i] == '3') v3++, k++;
        if (str[i] == '4') v4++, k++;
        if (str[i] == '5') v5++, k++;
        if (str[i] == '6') v6++, k++;
        if (str[i] == '7') v7++, k++;
        if (str[i] == '8') v8++, k++;
        if (str[i] == '9') v9++, k++;
    
    }
    cout << "v0=" << v0 << endl;
    cout << "v1=" << v1 << endl;
    cout << "v2=" << v2 << endl;
    cout << "v3=" << v3 << endl;
    cout << "v4=" << v4 << endl;
    cout << "v5=" << v5 << endl;
    cout << "v6=" << v6 << endl;
    cout << "v7=" << v7 << endl;
    cout << "v8=" << v8 << endl;
    cout << "v9=" << v9 << endl;
    cout << "k=" << k;

}

3)从键盘上输入一个字符串,假定该字符串的长度小于80,
试统计出该串中每一种英文字母(不区分大、小写)的个数并输出出来;

#include
using namespace std;

int main()
{
    char str[80];
    int v[25] = {};
    cin >> str;
    int k = 0;
    for (int i = 0; i < 80; i++)
    {
        for (int j = 0;j<25 ;j++)
        {
            if (str[i] == 'a' + j | str[i] == 'A' + j)
                v[j]++; k++;
        }

    }
    for (int i = 0; i < 25; i++)
    {
        cout << "v"<     }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/569235.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存