1. Enter a string that counts the number of uppercase, lowercase, spaces, numbers, and other characters. (Requires a character array)
#include <stdio.h># define N -intMain () {CharA[n]; inta1=0, b=0, c=0, d=0, e=0, i=0; printf ("input string: \ n"); 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 if(a[i]==' ') {D++; } Else{e++; }} printf ("There are%d in uppercase letters,%d in lowercase,%d for number,%d for space, and%d for others. ", a1,b,c,d,e); return 0;}
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.
#include <stdio.h>#include<string.h># define N -intMain () {CharA[n],b[n]; intI,c,d=3; printf ("set a password \ n"); Gets (a); printf ("Enter your password, there are three chances \ n"); for(i=0;i<3; i++) {gets (b); if(strcmp (A, b) = =0) {printf ("The password is correct \ n"); Break; } Else if(d!=1) {printf ("wrong,%d times left \ n", d1); D--; } Else{printf ("wrong password, no chance. \ n"); Break; } } return 0;}
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.
#include <stdio.h>#defineN 100intHuiChara[]);intMain () {inti,j; CharA[n]; printf ("Please enter a string \ n"); Gets (a); if(Hui (a)) {printf ("it's a palindrome \ n"); } Else{printf ("not a palindrome \ n"); }}intHuiChara[]) { intj=-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;}
Second, the experimental summary:
1.int C; while ((c = GetChar ())! = ' \ n ' && c! = EOF); You can clear the cache.
2. When entering a string,%s is not allowed to enter a space, and gets can enter a space.
3. Use the header file string.h except for the string handler function other than gets and puts.
4.scanf function input string cannot contain spaces, you need to use the gets function.
Third, the curriculum experience:
1. By now the code probably hit more than 1000 lines, just lifted the C language feeling this course is very mysterious, it must be difficult to learn, until after a semester to find that C language is mainly understanding, and so that they can fully understand, it becomes more simple.
2. The class must pay attention to listen, the class should also pay attention to the more refresher lessons, although the textbook and the teacher said there are some different, but in class also must read more books, do not worry about writing code.
3. I feel the technical blog submitted the form of work is very novel, keep up with the trend of the Times Ah!! Also can see other students ' homework, exchange with each other, timely correction. I will give the next session of the study younger sister recommended, very convenient, can better help them to learn.
11th Time Job