C language must memorize 100 codes, C language code collection (C language must memorize project codes)

1. You must memorize 100 codes in C language, and you must memorize project codes in C language.

How do beginners learn to code in C language? To read code and write C language, you must memorize 100 codes. I don’t know the direction of learning code? Can anyone show me the way? For C language, there are not many things to remember, only a few common statements and some keywords. The thousands or even tens of thousands of lines of code you see are written repeatedly using these statements and keywords. However, their logic The functions are quite different. How to quickly learn C language requires memorizing 100 codes. It is recommended to read and write more.

2. The C language that beginners must know must memorize 100 codes

1. You must memorize 100 codes in C language, a complete collection of C language codes

The first ------ multiplication table.

Use C language to output the 9*9 formula. There are 9 rows and 9 columns in total, i controls the rows and j controls the columns.  

2. You must memorize 100 codes of 4×4 array in C language

The function of the following program is to rotate a 4×4 array 90 degrees counterclockwise and then output it. The data of the original array is required to be randomly input. The new array is output in the form of 4 rows and 4 columns. Please complete the program in the blank space.

3. You must memorize 100 codes in C language, and you must memorize 100 codes in C language.

classical questions

There is a pair of rabbits. They give birth to a pair of rabbits every month from the third month after birth. After the baby rabbit grows to the third month, they give birth to a pair of rabbits every month. If the rabbits do not die, ask the rabbits of each month. What is the total number?

The pattern of rabbits is the sequence 1,1,2,3,5,8,13,21…  

4. You must memorize 100 code prime numbers in C language

Determine how many prime numbers there are between 101-200, and output all prime numbers and the number of prime numbers.

Program analysis: How to judge prime numbers: Use a number to divide 2 to sqrt (this number) respectively. If it can be divided evenly, it means that the number is not a prime number, otherwise it is a prime number. 

5. In C language, you must memorize 100 codes to complete the relevant codes

A number is called a "perfect number" if it is exactly equal to the sum of its factors. For example, 6=1+2+3. Program to find all perfect numbers within 1000.

6. You must memorize 100 codes in C language

triangle print

Programming to print right-angled Yang Hui triangle 

7. You must memorize 100 codes in C language

average score question

Enter the grades of 3 students in 4 courses through the keyboard, and find the average grade of each student and the average grade of each course. All scores are required to be put into an array with 4 rows and 5 columns. When inputting, use spaces between data for the same person and press Enter for different people. The last column and the last row contain the average score of each student and the average score of each course respectively. and overall class average.

#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. In C language, you must memorize 100 codes and output them in reverse

Improve the program to output the input string in reverse order, such as inputting windows and outputting swodniw.  

9. You must memorize 100 codes in C language.

The function of the following program is to delete the characters stored in c from the character array s. 

10. You must memorize 100 codes in C language----solve the sorting problem

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 input in the main function. Display the results on the screen and output them to the 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);
}

Output:

11. You must memorize 100 codes in C language to solve the problem of sorting from small to large

It is known that the elements in array a have been arranged in order from small to large. The function of the following program is to insert an input number into array a. After the insertion, the elements in array a are still arranged in order from small to large. 

12. You must memorize 100 codes in C language

replace output

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 all input in the main function. Replace the original string and The string after is 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. You must memorize 100 codes to search in C language

Search for 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. You must memorize 100 codes in C language

Use pointer variables to output structure array elements. 

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");    
/*用指针变量输出结构体数组元素。*/
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);
/*用数组下标法输出结构体数组元素学号和年龄。*/
for(i=0;i<5;i++)
printf("%d\t%d\t\n",stu[i].num,stu[i].age);
}

15. You must memorize 100 codes in C language. Fifteen

Create a simple linked list with three nodes

16. You must memorize 100 codes in C language and bubble sort

Bubble sorting, from small to large, the sorted results are output to the screen and the file myf2.out 

17. You must memorize 100 codes in C language, and you must memorize classic programs in C language that outputs strings.

Enter a string and determine whether it is a palindrome. A palindrome string is a string that is exactly the same when read left to right and right to left.

18. You must memorize 100 codes and write functions in C language

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 that the accuracy requirements are met. Please improve the function. Display the results on the screen and output to the file p7_3.out.

Guess you like

Origin blog.csdn.net/chengxuyuanlaow/article/details/127413020