C-language loop structure and cyclic control statements

Source: Internet
Author: User

Sometimes we may need to execute the same piece of code multiple times. In general, statements are executed sequentially: The first statement in a function executes first, followed by the second statement, and so on.

Programming languages provide a variety of control structures for more complex execution paths.

The loop statement allows us to execute a statement or group of statements multiple times.

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9D/F0/wKioL1mJICqSs2DmAABWSVO0OLs147.png-wh_500x0-wm_ 3-wmp_4-s_116382754.png "style=" Float:none; "title=" 2017-08-08_10-10-09.png "alt=" Wkiol1mjicqss2dmaabwsvo0ols147.png-wh_50 "/>

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/9D/F0/wKioL1mJICvgUbnJAABG0nxDqBo684.png-wh_500x0-wm_ 3-wmp_4-s_3968717418.png "style=" Float:none; "title=" 2017-08-08_10-10-24.png "alt=" Wkiol1mjicvgubnjaabg0nxdqbo684.png-wh_50 "/>

Own little Practice

Print Count

#include <stdio.h>int main () {int a,sum;printf ("Please enter number A:"), scanf ("%d", &a), sum = 1;do{printf ("*"); sum = sum + 1;} while (sum<=a);}

Top N Odd and

#include <stdio.h>int main () {int s,sum,n,i;printf ("Enter the top N:"), scanf ("%d", &n); s = 0;sum = 1;i = 1;while (i<=n ) {s = s +sum;sum = sum + 2;i = i + 1;} printf (the and of the first n items is:%d. ", s);}

Seeking primes

#include <stdio.h> #include "math.h" int main () {int a,n,i;printf ("Please enter the number to be judged: \ n"), scanf ("%d", &a); n = sqrt (a); for (i=2;i<=n;i=i+1) {if (a%n==0) break;} if (i==n+1) printf ("%d" is a prime number.) ", a); else printf ("%d is not a prime number.) ", a);}


This article from "Big Plum" blog, reproduced please contact the author!

C-language loop structure and cyclic control statements

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.