Introduction to C Programming--Program practice (bottom)

Source: Internet
Author: User

C language for some simple operation exercises.


Swap two numbers:

# include <stdio.h>int main (void) {int i = 3;int j = 5;int t;//Exchange The value of I with j T = I;i = J;j = t;printf ("i =%d, j =%d\n", I, j); return 0;}

Output Pyramids of any character at any level:

# Include<stdio.h>main () {int a,i,j; char c; printf ("Please enter pyramid layer, 30: \ n"), scanf ("%d", &a); printf ("Enter the characters to be output: \ n "); scanf ("%c", &c); for (i=a;i>0;i--) {  printf ("%*s", I, "");  For (j=0;j< (A-i) *2-1; j + +)  {   printf ("%c", c);  }  printf ("\ n"); }  return 0;}

Operation Result:



Operation:

# include <stdio.h>int main (void) {/*float i;i = 51/4;printf ("%f\n", i);p rintf ("%d%d%d%d%d\n", 3%3, 13%-3,-13 %3, -13%-3, -13%23, 3%5); */int m;int k = 10;m = (21>3) && (k=5),//m is Boolean, K=5 is true, False if and only if k=0, that is, 0 is false, other numbers are true printf ("M =%d, k=%d\n ", M, k);//When the left cannot determine the true and false value of M, the right side is executed; If the left side can determine the true and false m value, the right does not execute. && the left expression is false, the expression on the right will definitely not execute//| | When the expression on the left is true, the expression on the right will definitely not execute return 0;}


Three numbers sorted by:

# include <stdio.h>int main (void) {Double I, J, k;printf ("Please enter three numbers (separated by a space):"); scanf ("%lf%lf%lf", &i, &j, &A mp;k), if (i > J) {if (i > K) {printf ("Max:%lf\n", i), if (J > K) printf ("The size order of the number is:%lf >%lf >%lf\n", I, J, K); elseprintf ("The size order of the numbers is:%lf >%lf >%lf\n", I, K, j);} else{printf ("Max:%lf\n", K), if (i > J) printf ("The size order of the number is:%lf >%lf >%lf\n", K, I, J); elseprintf ("The size order of the number is:%lf > %lf >%lf\n ", K, J, I);}} Else{if (J > K) {printf ("Max:%lf\n", J), if (i > K) printf ("Size Order of the number:%LF >%lf >%lf\n", J, I, K); elseprintf ("Number of the large Small order:%lf >%lf >%lf\n ", J, K, I);} else{printf ("Max:%lf\n", K), if (i > J) printf ("The size order of the number is:%lf >%lf >%lf\n", K, I, J); elseprintf ("The size order of the number is:%lf > %lf >%lf\n ", K, J, I);}} return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Getting Started with C programming-program practice (bottom)

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.