11th Time Assignment

Source: Internet
Author: User

First, the contents of the experiment

1. Enter a string that counts the number of uppercase, lowercase, spaces, numbers, and other characters. (Requires a character array)

Code

1#include <stdio.h>2#include <string.h>3 #defineN 9994 intMain ()5 {6     intI,a=0, b=0, c=0, d=0, e=0;7     CharStr[n];8printf"Please enter a string: \ n");9 gets (str);Ten      for(i=0; str[i]!=' /'; i++) One     { A         if(str[i]>='A'&&str[i]<='Z') -         { -a++; the         } -         Else if(str[i]>='a'&&str[i]<='Z') -         { -b++; +         } -         Else if(str[i]>='0'&&str[i]<='9') +         { AC++; at         } -         Else if(str[i]==' ') -         { -d++; -         } -         Else in         { -e++; to         } +     } -printf"uppercase%d, lowercase%d, number%d, space%d, other%d \ n", a,b,c,d,e); the     return 0; *}

Run results

2. Use a character array for password verification, if the password is correct, the login succeeds, otherwise the login fails. The password allows you to enter three times.

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 intMain ()5 {6     intTime=3;7     Charpassword[]="Fengrunfa", input[Ten];8printf"Mission:input the password and you has only 3 chance.\n");9      DoTen     { One gets (input);  A         if(strcmp (password,input) = =0) -         { -printf"Mission Success,well done!\n"); the              Break; -         } -         Else -         { +printf"Mission failed,try again\n"); -time--; +         } A} while(time!=0); at     return 0; -}

Run results

3. Write a function that determines whether a string is a palindrome. If the Palindrome function returns a value of 1, otherwise the return value is 0. A palindrome is the same as reading and falling. such as "Level" "ABBA" and so on is a palindrome, but "ABCD" is not a palindrome. A palindrome function is called in the main function to judge the input string.

1# include <stdio.h>2# include <string.h>3# define N9994 intJudgeCharstr[n]);5 intMain ()6 {7     inti;8     CharStr[n];9printf"Please enter a string: \ n");TenI=judge (str); One     if(i==1) A     { -printf"string palindrome \ n"); -     } the     Else -     { -printf"string not palindrome \ n"); -     }  + return 0;  - }  + intJudgeCharStr[n]) A { at     inti,j=-1; - gets (str); -      for(i=0; str[i]!=' /'; i++) -     { -J + +; -     } in      for(i=0; i<=j;i++,j--) -     { to         if(str[i]==Str[j]) +         { -             return 1; the         } *         Else $         {Panax Notoginseng             return 0; -         } the     } +}

Run results

Summary of Knowledge points

SCANF can not accept space, Tab tab, enter, etc., and get can accept spaces, Tab tab and enter, etc. scanf can limit the length of the string, gets cannot

Experimental summary

strcmp can't spell wrong

Course Experience

I feel the beginner code like learning math problems, the problem-solving mode learned, naturally learned, ppt If you can send in the course before class, students can understand the general content of this class in advance, the class will be targeted to listen to those who do not understand the place;

In class, it's best to let the students do the following, imitate the examples, the students know how to do, then explain why, I myself feel that the first to say too professional terminology, the students will be a bit difficult to understand, and feel boring;

Just like I started to read the computer newspaper, those hardware names do not understand, feel no meaning, and then contact some large single-machine game, the computer has requirements configuration, know what CPU graphics memory is what to use after, then picked up the computer newspaper, look at those ssd,hdd,ddr4,i7 6700HQ, I know what that means.

More importantly, I also found the fun to read the computer newspaper, understand the latest technology trends, as long as there is a chance to see

This is just my own understanding of the code, perhaps only for my own, the game is also a string of code to write out, why not the code as a game, familiar with its meaning of each function, skilled operation and practice to get started?

Now play the game to play more and feel the game is a bunch of data, but different game complexity is different, perhaps the next stage, I will be more interested in how to make games and applications

Finally, also thanks to the teacher this half-year inculcation, these are just my own some of the cognitive feelings, hope to help teachers, some places may be said not very appropriate, but also hope that teachers forgive

11th Time Assignment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.