In: Computer Science
For the following questions, you can use any structure you have learned until now (While/Do-While/ for loops, if-statement, switch-case statement).
Question2: Find all prime numbers between 10 to 100.
hint: a prime number is a number that is divisible by 1 and itself. for example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
Since you have not mentioned which program to use I'm using C program -
Here we will use two loops 1st loop that will cycle from 10 to 100
Other loop will check for eligibility of prime for each number that the first loop cycles through
Here is the program -
#include <stdio.h>
int main()
{
int i, Number, count;
printf(" Prime Number from 10 to 100 are: \n");
//loop used to check from 10 to 100 for prime
for(Number = 10; Number <= 100; Number++)
{
count = 0;
//loop to check for prime
for (i = 2; i <= Number/2; i++)
{
if(Number%i == 0)
{
count++;
break;
}
}// loop for prime ends here
if(count == 0 && Number != 1 )
{
printf(" %d ", Number);
}
} //loop to check 10 to 100 ends here
return 0;
}
Output -
Thanks