loops.c सम्पादन

// This program displays a temperature conversion table showing Fahrenheit
// temperatures from 0 to 100, in increments of 10, and the corresponding
// Celsius temperatures using While, For, and Do loops.

#include "stdio.h"

void while_loop();
void for_loop();
void do_loop();

int main(void)
{
    while_loop();
    for_loop();
    do_loop();

    return 0;
}

void while_loop()
{
    double f;
    double c;
    
    printf("F°          C°\n");
    f = 0;
    while (f <= 100)
    {
        c = (f - 32) * 5 / 9;
        printf("%f = %f\n", f, c);
        f += 10;
    }
}

void for_loop()
{
    double f;
    double c;
    
    printf("F°          C°\n");
    for(f = 0; f <= 100; f += 10)
    {
        c = (f - 32) * 5 / 9;
        printf("%f = %f\n", f, c);
    }
}

void do_loop()
{
    double f;
    double c;

    printf("F°          C°\n");
    f = 0;
    do
    {
        c = (f - 32) * 5 / 9;
        printf("%f = %f\n", f, c);
        f += 10;
    } while (f <= 100);
}

कोशिश करो सम्पादन

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें सम्पादन