Question

1) Write a C program to print the prime numbers from 1 to 100. (A prime...

1) Write a C program to print the prime numbers from 1 to 100. (A prime integer is any integer that can be divided evenly only by itself and 1)

Requirement: Use an array to take the number from 1 to 100 and another array to take the prime number.

Homework Answers

Answer #1

Please follow the code and comments for description :

CODE :

/* C program to find all prime numbers from the inputted array */
#include<stdio.h>

int main() // driver method
{
   int ar[100], i, n, j, counter, res[100], m = 0; // local variables
  
   for(i = 0; i < 100; i++) // iterate and save the data
   {
       ar[i] = (i + 1);
   }
  
   printf("The Array is - \n"); // message
   for(i = 0; i < 100; i++)
   {
       printf("\t %d", ar[i]); // message
   }
  
   printf("\n");
   printf("\nAll the Prime Numbers in the Array are -\n"); // message
   for(i = 0; i < 100; i++) // iterate to calcualte the primes
   {
       counter = 0;
       for(j = 2; j < ar[i]; j++)
       {
           if(ar[i] % j == 0) // prime number condition
           {
               counter = 1;
               break;
           }
       }
       if(counter == 0) // if true
       {
            res[m] = ar[i]; // assign to another array
           printf("\t %d", res[m]); // message
           m++; // increment the count
       }
   }
   printf("\n"); // new line character
   return 0;
}


OUTPUT :


Hope this is helpful.

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
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers...
C++ PROGRAM. (C++ INTRO QUESTION) Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 55000 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules:...
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
Write a program to calculate the sum of all prime numbers between 100 and 200, including....
Write a program to calculate the sum of all prime numbers between 100 and 200, including. A prime number is a natural number greater than 1 and can only be divided by 1 and itself. For example, 5 is a prime number because 5 can only be divided by 1 and 5. we are currently using cin/cout, for /while loops
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, .........
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Write a program in python that prints the count of all prime numbers between A and...
Write a program in python that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2,...
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 the following in C: 2. An integer is said to be prime if it is...
Write the following in C: 2. An integer is said to be prime if it is divisible by only 1 and itself. Write a function called prime() that takes in one integer number, and returns 1 (true) if the number is prime and 0 (false) otherwise. Write a program to generate six random numbers between 1 to 100 and calls function prime() on each one to determine if it is prime or not.
use python Write a program that uses a for loop to display all prime numbers within...
use python Write a program that uses a for loop to display all prime numbers within the range [500, 800] (hint: prime numbers are numbers that have only 2 factors: 1 and themselves. You can use a loop function to check if a number has a factor other than 1 or itself using % operation)