search
HomeBackend DevelopmentC#.Net TutorialC language must memorize 18 classic programs that beginners of C language must know (collection)

C language must memorize 18 classic programs that beginners of C language must know (collection)

AC languageHow do beginners learn code, read code and write code? I want to learn code but don’t know the direction. Who can give me a direction? For In C language, there are not many things to remember, it is basically just a few common statements plus some keywords. The thousands or even tens of thousands of lines of code you see are all written repeatedly using these statements and keywords. It's just that their logical functions are different. So how to quickly get started with C language code? It is recommended to read more and write more.

1. The first of 18 classic programs that must be memorized in C language is the 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. C language must memorize 18 classic programs for 4×4 array

The function of the following program is to convert a 4 The ×4 array is rotated 90 degrees counterclockwise and then output. 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.

There is a pair of rabbits, the third one from birth A pair of rabbits are born every month starting from 3 months old, and another pair of rabbits are born every month after the rabbit reaches the third month. If the rabbits do not die, what is the total number of rabbits each month?

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

4. C language must Memorize 18 classic programs for prime numbers

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 determine 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.

If a number is exactly equal to its factor The sum is called a "perfect number". For example, 6=1+2+3. Program to find all perfect numbers within 1000.

6. C language must memorize 18 classic programs for triangle printing

Programming to print right-angled Yang Hui triangle

7. Question about the average score of 18 classic programs that must be memorized in C language

Enter the scores of 3 students in 4 courses through the keyboard, and find out respectively Average grade per student and average grade per 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. C language must memorize the reverse output of 18 classic programs

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

9. The ninth C language must memorize 18 classic programs

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

10. You must memorize 18 classic programs in C language----solve sorting problems

Write a void sort(int *x, int n) implements sorting the n data in the x array from large to small. n and array elements are input in the main function. Display the result on the screen and output it 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);
}

11. C language must memorize 18 classic programs to solve the problem of sorting from small to large

Known 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、C语言必背18个经典程序之替换输出

编写函数replace(char *s,char c1,char c2)实现将s所指向的字符串中所有字符c1用c2替换,字符串、字符c1和c2均在主函数中输入,将原始字符串和替换后的字符串显示在屏幕上,并输出到文件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);
}</stdio.h>

13、C语言必背18个经典程序之查找

在一个字串s1中查找一子串s2,若存在则返回子串在主串中的起始位置,不存在则返回-1。 

14、C语言必背18个经典程序,用指针变量输出结构体数组元素。

struct student
{
 int num;
 char *name;
char sex;
int age;
}stu[5]={{1001,"lihua",&#39;F&#39;,18},{1002,"liuxing",&#39;M&#39;,19},{1003,"huangke",&#39;F&#39;,19},{1004,"fengshou",&#39;F&#39;,19},{1005,"Wangming",&#39;M&#39;,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、C语言必背18个经典程序之十五

建立一个有三个结点的简单链表

16、C语言必背18个经典程序之冒泡排序

冒泡排序,从小到大,排序后结果输出到屏幕及文件myf2.out 

17、输出字符串的C语言必背经典程序

输入一个字符串,判断其是否为回文。回文字符串是指从左到右读和从右到左读完全相同的字符串。

18、C语言必背18个经典程序之编写函数

编写函数countpi,利用公式计算π的近似值,当某一项的值小于10-5时,认为达到精度要求,请完善函数。将结果显示在屏幕上并输出到文件p7_3.out中。

相关推荐:《C视频教程

The above is the detailed content of C language must memorize 18 classic programs that beginners of C language must know (collection). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
C# and .NET: Understanding the Relationship Between the TwoC# and .NET: Understanding the Relationship Between the TwoApr 17, 2025 am 12:07 AM

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

The Continued Relevance of C# .NET: A Look at Current UsageThe Continued Relevance of C# .NET: A Look at Current UsageApr 16, 2025 am 12:07 AM

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

From Web to Desktop: The Versatility of C# .NETFrom Web to Desktop: The Versatility of C# .NETApr 15, 2025 am 12:07 AM

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# .NET and the Future: Adapting to New TechnologiesC# .NET and the Future: Adapting to New TechnologiesApr 14, 2025 am 12:06 AM

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

Is C# .NET Right for You? Evaluating its ApplicabilityIs C# .NET Right for You? Evaluating its ApplicabilityApr 13, 2025 am 12:03 AM

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

C# Code within .NET: Exploring the Programming ProcessC# Code within .NET: Exploring the Programming ProcessApr 12, 2025 am 12:02 AM

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# .NET: Exploring Core Concepts and Programming FundamentalsC# .NET: Exploring Core Concepts and Programming FundamentalsApr 10, 2025 am 09:32 AM

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing C# .NET Applications: Unit, Integration, and End-to-End TestingTesting C# .NET Applications: Unit, Integration, and End-to-End TestingApr 09, 2025 am 12:04 AM

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)