Question

Write a C program that finds the odd, composite numbers between 10 and 500 in xterm...

Write a C program that finds the odd, composite numbers between 10 and 500 in xterm

a. Composite means it is not prime, i.e., “C” is composite if there exists an A and B such that A>1, B>1, and A*B = C.

b. Odd means that it is not divisible by 2.

c. Therefore “odd, composite”, means both odd and composite''

Output should be:

15 is a composite number.
21 is a composite number.
25 is a composite number.
27 is a composite number.
33 is a composite number.
35 is a composite number.

and so on

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

//function to check a numebr is prime or not
int checkPrime(int n)
{
   int i;
   for(i = 2; i <= n/2; i++)
   {
       if(n % i != 0)
           continue;
       else
           return 1;
   }
   return 0;
}
int main()
{
//variable declaration
int i;
//display the number
   for(i=10; i<=500; i++)
   {
   //if the numebr is odd and composite both
   if(i%2!=0 && checkPrime(i))
   printf("%d is a odd and composite number\n", i);
   else
   {
   //if the number is odd number
   if(i%2!=0)
   printf("%d is a odd number\n", i);
   //if the number is composite number
   if(checkPrime(i))
   printf("%d is a composite number\n", i);
   }
   }
   return 0;
}

OUTPUT:

10 is a composite number                                                                                                        

11 is a odd number                                                                                                              

12 is a composite number                                                                                                        

13 is a odd number                                                                                                              

14 is a composite number                                                                                                        

15 is a odd and composite number                                                                                                

16 is a composite number                                                                                                        

17 is a odd number                                                                                                              

18 is a composite number                                                                                                        

19 is a odd number                                                                                                              

20 is a composite number                                                                                                        

21 is a odd and composite number                                                                                                

22 is a composite number                                                                                                        

23 is a odd number                                                                                                              

24 is a composite number                                                                                                        

25 is a odd and composite number                                                                                                

26 is a composite number                                                                                                        

27 is a odd and composite number                                                                                                

28 is a composite number                                                                                                        

29 is a odd number                                                                                                              

30 is a composite number                                                                                                        

31 is a odd number                                                                                                              

32 is a composite number                                                                                                        

33 is a odd and composite number                                                                                                

34 is a composite number                                                                                                        

35 is a odd and composite number                                                                                                

36 is a composite number                                                                                                        

37 is a odd number  

Add a comment
Know the answer?
Add Answer to:
Write a C program that finds the odd, composite numbers between 10 and 500 in xterm...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java program: Write a program which displays the following list on the screen and asks the...

    java program: Write a program which displays the following list on the screen and asks the user to enter either 1 or 2 and perform one of the operations based on the user’s input. If the user enters any other character other than 1 or 2 then display “wrong choice”. LIST OF OPERATIONS 1. Buzz Number                      2. Consecutive Odd numbers Note: A BUZZ number is a number which either ends with 7 or is divisible by 7. Sample input 27...

  • Question 1: Write a python program that finds all numbers divisible by 7 but not multiple...

    Question 1: Write a python program that finds all numbers divisible by 7 but not multiple of 5. The range of number for searching is between 2000 and 3200 (both included). Output should be printed in a comma-separated sequence on a single line .

  • Write a program in a script file that finds the smallest odd integer that is also...

    Write a program in a script file that finds the smallest odd integer that is also divisible by 3 and whose cube is greater than 4000. Use a loop in the program. The loop should start from 1 and stop when the number is found. The program should print the message: The required number is: [and then prints the number]

  • c++ write a program to calculate and store the first 10 prime numbers. Recall that a...

    c++ write a program to calculate and store the first 10 prime numbers. Recall that a prime number is divisible by 1 and itself. Function to use in program : isPrime

  • 8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...

    8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7. ​ (b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7 (c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7 (d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both...

  • Write a program that finds and output all of the prime numbers between 2 to 2000...

    Write a program that finds and output all of the prime numbers between 2 to 2000 to the display screen. You are to declare any required array in main and pass them to your function sieve that will process the array.C++

  • Application program           Program name      PrimeNumbers.cpp           Problem background:        &n

    Application program           Program name      PrimeNumbers.cpp           Problem background:                    In mathematics, a PRIME number is a number that is divisible by only                    itself and 1.           Examples:                    2, 3, 5, 7, 11 are all primes                    these are not primes the number 4        divisible by 2 the number 6        divisible by 2 and 3 the number 12       divisible by 2, 3, 4, and 6 Write a C program to find all the prime numbers between 0 and...

  • Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the...

    Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the console (inclusive). The identified prime numbers must be stored in an array . The inputted number should be between 0 and 1000 (inclusive). array is large enough to o Make sure your hold all the prim e numbers. Dynamic memory allocation is not required for this assignment, so you can have unused space in your array Make sure you can handle the cases of...

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • write a python program which finds three consecutive odd numbers whose sum adds up to 45...

    write a python program which finds three consecutive odd numbers whose sum adds up to 45 and return a list of the numbers in ascending order do not use any other packages such as numpy or math

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT