Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
779 B
4
Indexable
Never
//Print Prime numbers upto 100

#include <stdio.h>

int main()
{
    int n = 2;
    while (n <= 100)
    {
        int isPrime = 1;
        for (int i = 2; i < n; i++)
        {
            if (n % i == 0)
                isPrime = 0;
        }
        if (isPrime)
            printf("%d\n", n);
        n++;
    }
}



//Print All Perfect numbers below 100

#include <stdio.h>

int main() {
    int sum;

    printf("Perfect numbers below 100 are:\n");

    for (int i = 1; i < 100; i++) {
        sum = 0;
        for (int j = 1; j < i; j++) {
            if (i % j == 0) {
                sum += j;
            }
        }
        if (sum == i) {
            printf("%d ", i);
        }
    }

    printf("\n");
    return 0;
}
Leave a Comment