第十一次作业

第一题:

实验代码:

#include<stdio.h>
#define n 100
int main()
{
    char a[n];
    int i,a1=0,b=0,c=0,d=0;
    printf("Please input the string:
");
    gets(a);
    for (i=0;a[i]!='';i++)
    {
        if(a[i]>='A'&&a[i]<='Z')
        {
            a1++;
        }
        else if(a[i]>='a'&&a[i]<='z')
        {
            b++;
        }
        else if(a[i]>='0'&&a[i]<='9')
        {
            c++;
        }
        else
        {
            d++;
        }
    }
    printf("%d capital letters,
%d lowercase letters,
%d digits,
%d others.
",a1,b,c,d);
    return 0;
}

运行结果:

第二题:

题目要求:

实验代码:

#include<stdio.h>
#include<string.h>
#define n 100
int main()
{
    char a[n],b[n];
    int i,c,d=3;
    printf("Please set a password:)    :
");
    gets(a);
    printf("Please input the password,you have 3 chances.↖(^ω^)↗
");
    do
    {
        gets(b);
        if(strcmp(a,b)==0)
        {
            printf("You are right!O(∩_∩)O~~
");
            break;
        }
        else if (d!=1)
        {
            printf("You are wrong,you have %d chances. ̄へ ̄
",d-1);
            d--;
        }
        else
        {
            printf("You are wrong,you have no chance./(ㄒoㄒ)/~~
");
            break;
        }
    }
    while(d!=0);
    return 0;
}

运行结果:

第三题:

实验代码:

#include<stdio.h>
#define n 100
int compare(char a[]);
int main()
{
    int i,j;
    char a[n];
    printf("Please input the English chring:
");
    gets(a);
    if(compare(a))
    {
        printf("This is palindrome
");
    } 
    else
    {
        printf("This is not palindrome
");
    }
} 
int compare(char a[])
{
    int j=-1,i;
    for(i=0;a[i]!='';i++)
    {
        j++;
    }
    for(i=0;i<j;i++,j--)
    {
        if(a[i]!=a[j])
        {
            return 0;
        }
    }
    return 1;
}

运行结果:

实验总结:

第一题与之前的判断字符异曲同工,只是把字符放进字符串中,对大小写字母和数字,字符进行判断。输出的时候由于是输入中文符号,而中文符号一个符号占两个字节,所以输入了四个中文符号,输出八个其他符号,误以为程序错了...

对于密码验证的代码,上课没听懂...后来看看室友大神的代码...看懂了- -,自己写起来好费劲...郁闷 ̄へ ̄

第三个代码也不会...宇哥讲了讲懂啦⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄,感谢宇哥么么哒~

嗯...还得是多用心吧!把写过的代码都认真过一遍- -,加油咯↖(^ω^)↗

课程体会:

1.估计大概有一千多代码...c语言程序设计在我看来是编程程序的一个工具。

2.代码一定要多写,经常练习,像我这样懒的人,不好好写代码真的是不行...唉!

3.我很喜欢这种提交作业的方式,因为我们提交作业后,老师和学长会很细心的给我们批改提意见,对自己的提升有很大的帮助。如果学弟学妹入学,我也会推荐这种方式,对自己的学习有很大帮助。

4.我觉得现在这样已经很完美了!

原文地址:https://www.cnblogs.com/jj4529926/p/6171952.html