Home

A program to print PRIME numbers below 100

C Programming Language 041

The following code shows how to write a program to print PRIME numbers below 100 using a for loop.

Program

#include <stdio.h>

void main()
{
    int i, k, count;
    for (k = 1; k <= 100; k++)
    {
        count = 0;
        for (i = 1; i <= k; i++)
        {
            if (k % i == 0)
            {
                count++;
            }
        }

        if (count == 2)
        {
            printf("%d\t", k);
        }
    }

    printf("\n");
}

Result

2       3       5       7       11      13      17      19      23      29      31      37      41      43     47       53      59      61      67      71      73      79      83      89      97


Last Updated on

Next Post: GraphProtocol: TS2322 null assignment in Subgraph →

Comments