C Language Practice

Source: Internet
Author: User
Tags goto

#include <stdio.h>intMainvoid ){        Doublenumber1=0.0; DoubleNumber2=0.0; CharOperation =0; printf ("\nenter the calculation \ n"); scanf ("%lf%c%lf",&number1,operation,&number2); Switch(operation) { Case '+': printf ("=%LF", number1+number2);  Break;  Case'-': printf ("=%LF", number1-number2);  Break;  Case'*': printf ("=%LF", number1*number2);  Break;  Case '/':            if(number2!=0) printf ("=%LF", number1/number2); Elseprintf ("wrong number2");  Break ;  Case '%':            if((Long) number2==0) printf ("Error"); Else ; printf ("=%LF",(Long) number1% (Long) number2);  Break; default: printf ("AIIIIIIIII");  Break; }        return 0;}
The system of the engine room can not be executed, also very silent ....

#include <stdio.h>intMain () {intI=1; printf ("********************");  for(;i< A; i++) printf ("\n* *"); printf ("\n********************"); return 0;}
Print Small Squares

#include <stdio.h>int  main () {            for (int k=1, j=2; k <=5; ++k,j=j+2)        printf ("\n%-5d", k*j);     return 0 ;} Print several numbers multiplied by

#include <stdio.h>intMain () {Longsum =0l; intCount =0; printf ("\nenter The number of integers you want to summed"); scanf ("%d",&count);   for (int i=1; i<=count;i++) sum+ =  i;    
The above code can be replaced with

for (int i=1;i<=count;sum+=i++); The loop statement is empty, and then the range of the for loop can be found to be the end of the tube to the first semicolon.

The above code can be replaced with
for (int i=count;i>=1;sum+=i--); Inverse operation
printf ("%ld", sum); return 0 ; }
>>6
Back to 6+5+4+3+2+1

an infinite loop only enters N to jump out of # include<stdio.h>#include<ctype.h>//Remember that the ToLower () function must haveintMain () {CharA=0;  for (;;) {printf ("y/n?"); scanf ("%c",&a); if(ToLower (a) = ='N')     Break; }    return 0;}


#include <stdio.h>#include<ctype.h>intMain () {CharA=0; DoubleTotal=0.0; DoubleValue=0.0; intCount =0; printf ("\nthis program ...."); for(;;) {printf ("\nenter a value:"); scanf ("%LF",&value); Total+=value; ++count; printf ("Do you want another value?"); scanf ("%c",&a); if(ToLower (a) = ='Q') Break; } printf ("%-2LF", total/count); return 0;} The letter and the number, and how did he know it before and after?

#include <stdio.h>#include<ctype.h>intMain () {intchosen = A; intguess=0; intCount=3;  for(; count>=1; count--) {printf ("\nenter The number you guess"); scanf ("%d",&guess); if(guess==chosen) {printf ("Congratulation"); Gotom;} if((guess> the)|| (guess<1)) printf ("Error"); } printf ("\n\nshibai"); m:printf ("\nyes"); }//goto m; superfluous. Direct can be used with return 0;
Jump out of all direct end, not to break
or | |
and &&
Don't be mistaken.

C Language Practice

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.