1. Enter a string that counts the number of uppercase, lowercase, spaces, numbers, and other characters. (Requires a character array)
#include <stdio.h>intMain () {intD=0, x=0, k=0, s=0, q=0, I; Chartj[ -]; printf ("Please enter a character!! \ n"); Gets (TJ); for(i=0; I<strlen (TJ); i++) { if(tj[i]>='a'&&tj[i]<='Z') {x++; } Else if(tj[i]>='A'&&tj[i]<='Z') {D++; } Else if(tj[i]>='0'&&tj[i]<='9') {s++; } Else if(tj[i]==' ') {k++; } Else{Q++; }} printf ("lowercase letters have%d\n capital letters with%d\n numbers have%d\n spaces have%d\n other characters have%d\n total%d\n", X,d,s,k,q,i); 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>intMain () {intI=0; Chara[]="1998080", input[8]; printf ("Please enter the password \ n"); scanf ("%7s", input); while(1) { if(strcmp (a,input) = =0) {printf ("you are welcome!! \ n"); Break; } Else{printf ("input Error! \ n"); I++; if(i/3==1) {printf ("you have no chance to enter the password!!! \ n"); Break; }} scanf ("%7s", input); } 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>#include<string.h>intMain () {inti,x,m=1, n=1, H; Charhw[ -]; printf ("Please enter a character \ n"); Gets (HW); X=strlen (HW); for(i=0; I<strlen (HW); i++) { if(hw[x-i-1]==Hw[i]) {m=-1; } Else{n=0; }} H=m*N; if(h==-1) {printf ("This is a palindrome number!! \ n"); } Else{printf ("This is not a palindrome number!! \ n"); } return 0;}
Experimental summary
1,char if the symbol is a single quotation mark when assigning a value to a shape variable
2, each string system automatically ends with "s", so the character length is one more
Course Experience
1, how to write 1000 lines to go up!? The knowledge of C is not as simple as it is imagined.
2, write C language to open the mind, to be creative
3, no view, help is can look at other people's ideas, procedures, for their own reference. No improvement, very good, recommended to learn younger sister
4, no suggestions and comments are very dedicated to
11th Time Assignment