Prime Numbers) Write a program to calculate and print a list of all prime numbers from 1 to 100.
C programming
#include <stdio.h> int isPrime(int num) { int i; if (num <= 1) return 0; if (num % 2 == 0 && num > 2) return 0; for (i = 3; i <= num / 2; i += 2) { if (num % i == 0) return 0; } return 1; } int main(){ int i = 2; while(i<100){ if(isPrime(i)){ printf("%d\n",i); } i++; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.