search
HomeCommon ProblemWhat does while mean in C language?

What does while mean in C language?

May 14, 2019 am 10:28 AM
while loop

The while in C language is a basic loop mode in computers. It means that when the expression is true, the prediction is executed, and when the expression is false, the loop is jumped out.

What does while mean in C language?

#The while in C language is a loop statement and a basic loop mode of the computer. Enter the loop when the conditions are met, and jump out if the conditions are not met

The execution sequence of while

The execution sequence of while loop is very simple, its format is:

while (表达式)
{
        语句;
}

When the expression is true, execute the following statement; after the statement is executed, judge whether the expression is true. If it is true, execute the following statement again; then judge whether the expression is true... and so on. Continue until the expression is false and break out of the loop. This is the execution sequence of while.

Write a program below to implement this function:

Calculate the value of (1-1/3 1/5-1/7 1/9-1/11…)*4.

# include <stdio.h>
int main(void)
{
    int i = 1;
    int j = 1;
    double sum = 0;  //结果肯定是小数, 所以要定义成double或float型
    while (1.0/i > 1e-6)  /*当1/i小于10的-6次方时停止循环。这个循环条件是自己定的, 定得越小最后的结果就越精确。
    注意1一定要写成小数的形式即1.0*/
    {
        sum += (1.0 / i) * j;
        i+=2;
        j = -j;  //实现正负交替
    }
    sum *=4;
    printf("sum = %lf\n", sum);  //double是%lf, 取6位小数是%.6
    return 0;
}

The output result is:
sum = 3.141591

The above is the detailed content of What does while mean in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)