Some simple examples of C language

Source: Internet
Author: User


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.