I made a code to determine the number of digits, but I'm curious why it's not working

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
    int i, j;
    int count = 0;
    int num;
    int check;
    printf("Enter an integer greater than or equal to 2 :");
    scanf("%d", &num);

    for (i = 2; i <= num; i++);
    {
        check = 0;
        for (j = 2; j < i; j++)
        {
            if ((i % j) == 0)
            {
                check = 1;
                break;
            }
        }
        if (check == 0)
        {
            printf("%5d", i);
            count++;
            if (count % 5 == 0)
            {
                printf("\n");
            }
        }
    }

    return 0;
}

I hit 100 and now I get 101 We need to find more than two prime numbers, but why is that? I'll be waiting for the reply.

c

2022-09-20 11:11

1 Answers

The code below is invalid.

for (i = 2; i <= num; i++);

There is ; at the end of the for loop code, and you have to erase it like below.

for (i = 2; i <= num; i++)


2022-09-20 11:11

If you have any answers or tips


© 2022 pinfo. All rights reserved.