A program is a step-by-step, step-by-step invocation of a variable that can be re-assigned.
1.Hello world! Program
#include <stdio>//To tell the compiler to include standard input/output libraries in this program
the int main ()//C language starts with the main () function, and I don't know what the int void means?
{
printf ("Hello world!\n"); This statement will "hello,world! \ n "Call the printf function as a parameter
return 0; Here is the termination procedure, to this end. The following statements are not executed either.
}
\ n represents only one character. A sequence of escape characters similar to \ n provides a common, extensible mechanism for representing characters or invisible characters that cannot be entered. In addition, the escape character sequence provided by the C language includes the following: \ t for tabs, \b for the fallback character, and \ for double quotation marks; \ \ for the backslash character itself.
2. Two number swap
#include <stdio.h>
void Main ()
{
int a=5,b=10;
int tmp;
tmp=a;a=b;b=tmp;
printf ("a=%d\nb=%d\n", A, b);
}
3.99 Multiplication Table
1*1=1;
1*2=2 2*2=4;
1*3=3 2*3=6 3*3=9;
#include <stdio.h>
Main ()
{
int i,j;
for (i=1;i<10;i++)
{
for (j=1;j<=i;j++)
{printf ("%d*%d=%d", J,i,j*i);}
printf ("\ n");
}
}
4. Using the selection sorting method: Ascending order of N random numbers entered
#include <stdio.h>voidMain () {inta[ -],n,i,j,t; printf ("N="); scanf ("%d",&N); for(i=0; i<n;i++) scanf ("%d",&A[i]); for(i=0; i<n-1; i++) for(j=i+1; j<n;j++) if(A[i]>a[j]) {t=a[i];a[i]=a[j];a[j]=T;} for(i=0; i<n;i++) printf ("%d \ n", A[i]);}
N=5 12 5 86 3 7
First for: After executing i=0:3 12 86 5 7
5.1+2+...+100=?
#include <stdio.h>
Main ()
{
int i,sum=0;
for (i=1;i<101;i++) {sum + = i;}
printf ("sum=%d\n", sum);
}
Some simple examples of C language