Question

Prime Numbers) Write a program to calculate and print a list of all prime numbers from...

Prime Numbers) Write a program to calculate and print a list of all prime numbers from 1 to 100.

C programming

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a C++ program that display a prime numbers between 1 and 100 number. Plase print...
write a C++ program that display a prime numbers between 1 and 100 number. Plase print the remaining primes by “dots” For gexample The output should appear like The prime numbers between 1 and 100 are: 1, 2, 3, 5, 7, .........
C programming language. Write a program to print reverse of all the numbers from m to...
C programming language. Write a program to print reverse of all the numbers from m to n using functions with arguments and no return type. The inputs in the program will be m and n variables and need to take these variables as arguments.
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
Write an R code to print out all even numbers from the following numbers list in...
Write an R code to print out all even numbers from the following numbers list in the same order they are received. Write the code so it does not print any numbers that come after 83. numbers = [951, 40, 84, 51, 60, 69, 48, 19, 61, 85, 98, 50, 72, 47, 44, 61, 83, 65, 41, 51, 63, 61, 65, 75, 21, 30, 84, 92, 23]
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
Write a smallest_gap(start_num, end_num) function that finds smallest gap between successive primes, considering prime numbers in...
Write a smallest_gap(start_num, end_num) function that finds smallest gap between successive primes, considering prime numbers in the range from start_num to end_num (inclusive). For example, start_num = 5 and end_num = 12, the prime numbers in that range are: [5, 7, 11]. The smallest gap between any two prime numbers in this list is 2, so the function would return 2. Some example test cases (include these test cases in your program): >>> print(smallest_gap(5, 12)) 2 # The primes between...
Write a C program that when you type in five numbers, it will print the number...
Write a C program that when you type in five numbers, it will print the number from the smallest one to the largest one.(if you type in 2, 1, 3, 5, 4, the output will be 1, 2, 3, 4, 5 ) You may need more than one function to complete this mission.
Write a loop to print a list of numbers starting at 64 and ending at 339....
Write a loop to print a list of numbers starting at 64 and ending at 339. Justify your syntax.
Write a program to take input of two integer variable a and b. After taking input...
Write a program to take input of two integer variable a and b. After taking input of these variables print all the palindrome numbers from a to b. I need this is C programming language.
.Write a for loop to create a list of all the odd numbers between 15 and...
.Write a for loop to create a list of all the odd numbers between 15 and up to and not including 75. Write a second for loop to find the average value in the list, then print it.