1, C language must recite 18 classic programs, and C language beginners must know
A beginner of C language how to learn code, read code and write code. I want to learn code. I don't know the direction. Who can point out a direction for me? For C language, there are not many things to remember. It is basically a few common statements and some keywords. The thousands or even tens of thousands of lines of code you see are written repeatedly with these statements and keywords. But their logic functions are different. How to quickly get started with C language code? It is recommended to read and write more. The following is a small compilation of C language, which must recite 18 classic programs.
A lot of C language must be sorted into a compressed package. WeChat official account is called "C and C plus" reply: "YM" can be obtained.
2, C language learning related C language must recite 18 classic programs
1. C language must recite 18 classic programs. The first one is the multiplication table.
Output 9 * 9 Dharma formula in C language. There are 9 rows and 9 columns in total, i control row and j control column.
2. C language must recite 4 of the 18 classic programs × 4 array
The function of the following program is to put a 4 × The array of 4 is output after rotating 90 degrees counterclockwise. The data of the original array is required to be input randomly. The new array is output in the form of 4 rows and 4 columns. Please improve the program in the blank space.
3. C language must memorize 18 classical programs
There is a pair of rabbits. They give birth to a pair of rabbits every month from the third month after birth. When the little rabbits grow to the third month, they give birth to another pair of rabbits every month. If the rabbits do not die, what is the total number of rabbits every month?
The rule of rabbits is sequence 1,1,2,3,5,8,13,21
4. C language must memorize the prime numbers of 18 classic programs
Judge how many primes there are between 101-200, and output all primes and the number of primes.
Program analysis: method of judging prime numbers: use a number to remove 2 to sqrt (this number) respectively. If it can be divided, it indicates that this number is not a prime number, on the contrary, it is a prime number.
5. C language must memorize the completion related code of 18 classic programs
If a number is exactly equal to the sum of its factors, it is called "perfect". For example, 6 = 1 + 2 + 3 Program to find all completions within 1000.
6. C language must memorize 18 classic programs for triangle printing
Programming and printing right angle Yanghui triangle
7. The average score of 18 classic programs in C language
Input the scores of 3 students and 4 courses through the keyboard to calculate the average score of each student and the average score of each course respectively. All scores are required to be put into an array of 4 rows and 5 columns. When entering, use spaces between the data of the same person and press enter for different people. The last column and last row respectively put the average score of each student, the average score of each course and the total average score of the class.
#include <stdio.h> #include <stdlib.h> main() { float a[4][5],sum1,sum2; int i,j; for(i=0;i<3;i++) for(j=0;j<4;j++) scanf("%f",&a[i][j]); for(i=0;i<3;i++) { sum1=0; for(j=0;j<4;j++) sum1+=a[i][j]; a[i][4]=sum1/4; } for(j=0;j<5;j++) { sum2=0; for(i=0;i<3;i++) sum2+=a[i][j]; a[3][j]=sum2/3; } for(i=0;i<4;i++) { for(j=0;j<5;j++) printf("%6.2f",a[i][j]); printf("\n"); } }
8. C language must memorize the reverse output of 18 classic programs
Improve the program to output the input string in reverse order, such as windows and swodniw.
9. The ninth C language must recite 18 classic programs
The function of the following program is to delete the characters stored in c from the character array s.
10. C language must memorize 18 classic programs -- solving sorting problems
Write a void sort(int *x,int n) to sort the N data in the X array from large to small. N and array elements are entered in the main function. The results are displayed on the screen and output to a file p9_1.out
#include<stdio.h> void sort(int *x,int n) { int i,j,k,t; for(i=0;i<n-1;i++) { k=i; for(j=i+1;j<n;j++) if(x[j]>x[k]) k=j; if(k!=i) { t=x[i]; x[i]=x[k]; x[k]=t; } } } void main() {FILE *fp; int *p,i,a[10]; fp=fopen("p9_1.out","w"); p=a; printf("Input 10 numbers:"); for(i=0;i<10;i++) scanf("%d",p++); p=a; sort(p,10); for(;p<a+10;p++) { printf("%d ",*p); fprintf(fp,"%d ",*p); } system("pause"); fclose(fp); }
11. C language must memorize 18 classic programs to solve the sorting from small to large
It is known that the elements in array a have been arranged from small to large. The function of the following program is to insert an input number into array A. after insertion, the elements in array a are still arranged from small to large
12. C language must memorize the replacement output of 18 classic programs
Write the function replace(char *s,char c1,char c2) to replace all characters c1 in the string pointed to by s with c2. The string, characters c1 and c2 are input in the main function. The original string and the replaced string are displayed on the screen and output to the file p10_2.out
#include<stdio.h> replace(char *s,char c1,char c2) { while(*s!='\0') { if (*s==c1) *s=c2; s++; } } main() { FILE *fp; char str[100],a,b; if((fp=fopen("p10_2.out","w"))==NULL) { printf("cannot open the file\n"); exit(0); } printf("Enter a string:\n"); gets(str); printf("Enter a&&b:\n"); scanf("%c,%c",&a,&b); printf("%s\n",str); fprintf(fp,"%s\n",str); replace(str,a,b); printf("The new string is----%s\n",str); fprintf(fp,"The new string is----%s\n",str); fclose(fp); }
13. Search of 18 classic programs in C language
Find a substring s2 in a string s1. If it exists, return the starting position of the substring in the main string. If it does not exist, return - 1.
14. C language must memorize 18 classic programs and output structural array elements with pointer variables.
struct student { int num; char *name; char sex; int age; }stu[5]={{1001,"lihua",'F',18},{1002,"liuxing",'M',19},{1003,"huangke",'F',19},{1004,"fengshou",'F',19},{1005,"Wangming",'M',18}}; main() {int i; struct student *ps; printf("Num \tName\t\t\tSex\tAge\t\n"); /*Output structure array elements with pointer variables.*/ for(ps=stu;ps<stu+5;ps++) printf("%d\t%-10s\t\t%c\t%d\t\n",ps->num,ps->name,ps->sex,ps->age); /*Use the array subscript method to output the student number and age of the array elements of the structure.*/ for(i=0;i<5;i++) printf("%d\t%d\t\n",stu[i].num,stu[i].age); }
15. C language must memorize 15 of 18 classic programs
Establish a simple linked list with three nodes
16. C language must memorize the bubble sorting of 18 classic programs
Bubble sorting, from small to large, and the sorted results are output to the screen and file myf2 out
17. C language for outputting strings must recite classic programs
Enter a string to determine whether it is a palindrome. Palindrome strings are strings that are read from left to right and read exactly the same from right to left.
18. C language must memorize the writing functions of 18 classic programs
Write the function countpi and use the formula to calculate the approximate value of π. When the value of a certain item is less than 10-5, it is considered to meet the accuracy requirements. Please improve the function. The results are displayed on the screen and output to a file p7_3.out.
3, So far, this paper ends with a simple list of 18 classic programs that must be memorized in C language
C language has been written back to 18 classic programs as a compressed package, focusing on WeChat official account: "C and C plus" reply: "YM" can be obtained.