C Concepts

Written on June 28, 2024

1 min. read

Here is an example using while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cs50.h>
#include <stdio.h>

int main(void)
{
    // variable declaration
    int count, counter;

    // reading input from keyboard
    count = get_int("Upto how many numbers you want to print? ");
    
    counter = 1;
    while (counter <= count)
    {
        printf("%i ", counter);
        counter = counter + 1;
    }
    printf("\n");
}