Question

Create your own unique While-End or (For End) repetition C code. You decide the theme. Be...

Create your own unique While-End or (For End) repetition C code. You decide the theme. Be sure to provide an overview of what your repetition structure is doing. Please keep the design simple for this exercise. Just a few lines of code is all that is needed for this response. This should be code you wrote for an application that is interesting to you. In other words, make it your own and have fun with it. Provide the C code and a screen capture showing the results of testing your code in an online compiler. Be sure to test your code with several test cases and show your test case table.

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

SOURCE CODE:

#include <stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k;
k=1;
while(j!=0)//While loop runs until user enters 0
{

  
printf("Enter a number to check if prime or not\n");
scanf("%d",&j);//Enter a number to check if number is prime or not
getchar();
if(j==1)//If number is 1, it is not a prime
{
printf("Not a prime");
break;
}
if(j==2)//If number is 2, it is a prime
{
printf("It is a prime");
break;
}
/*Code to find if number is prime or not*/
for(i=2;i<j;i++)//Run the loop until i becomes number-1
{
if(j%i==0)k=0;//If at any point in the loop, the remainder of i and the number becomes 0, the value of k changes to 0
}
if(k==1) printf("It is a prime");//If value of k remained unchanged, print it is a prime
else printf("It is not a prime");//If value of k changed, print not a prime
}
return 0;
  
}
SCREENSHOTS:
Ksource code close fullscreen 6 k-1; 7 while(jl-e) 9 fflush(stdin); 10 printf(Enter a number to check if prime or not\n); s input Output syntax highlightsyntax highlight input Output It is not a primeEnter a number to check it prime or not It is a prime Success time: 0 memory:

Add a comment
Know the answer?
Add Answer to:
Create your own unique While-End or (For End) repetition C code. You decide the theme. Be...
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
  • Homework 4 – Create your own Function Create your own function in C that accepts one...

    Homework 4 – Create your own Function Create your own function in C that accepts one input number and returns a double number. The themes for the functions should be one of the following:  Calculates 3.14 times of the square of input number. For example, if 2 is input then 12.56 should be returned. (e.g. 3.14*2*2 = 12.56)  Divides the number by 3 and returns the result. For example, if 6 was input then 2.0 should be returned....

  • Application Exercises – 1.15“Personal Mission Statement and Code of Conduct” Introduce yourself to the class by...

    Application Exercises – 1.15“Personal Mission Statement and Code of Conduct” Introduce yourself to the class by articulating your own personal statement. Do a bit of research first (as the textbook suggests). Then, in your initial DB post write a few sentences to introduce yourself and to mention the sources or examples you relied on to compose your personal mission statement and code of conduct. Then, attach your document. Application Exercis 1.15 Personal Mission Statement and Code of Conduct (LO 1.3)...

  • You decide to take advantage of the current online dating craze and start your own Web...

    You decide to take advantage of the current online dating craze and start your own Web site. You know that you have 450 people who will sign up immediately and, through a careful marketing research and analysis, determine that membership can grow by 27 percent in the first two years, 22 percent in year 3, and 18 percent in Year 4. How many members do you expect to have at the end of four years? (Round intermediate calculations to 6...

  • You decide to take advantage of the current online dating craze and start your own Web...

    You decide to take advantage of the current online dating craze and start your own Web site. You know that you have 550 people who will sign up immediately and, through a careful marketing research and analysis, determine that membership can grow by 29 percent in the first two years, 22 percent in year 3, and 18 percent in Year 4. How many members do you expect to have at the end of four years? (Round intermediate calculations to 6...

  • Python Code Question# 1 General Instructions Create a class called LawnService that takes in the length...

    Python Code Question# 1 General Instructions Create a class called LawnService that takes in the length and width of a yard, along with the current state of the yard. The currect state can be: poor, acceptable or great. Within this class include a constructor that will assign these values to attributes. Additionally create three methods that will be named and do the following: *DetermineApplication: This method will focus on the lawn status attribute. If the status is poor, the lawn...

  • Class - Hello - you must convert the pseudocode in Week 3 HW2 into C code...

    Class - Hello - you must convert the pseudocode in Week 3 HW2 into C code and run it and then show and discuss the output. Homework 2 – Test Case Creation Using the following pseudocode, provide 5 unique test cases that would help validate your algorithm. Be sure to place the test cases in a table showing the input values, and expected output for each test case. Write "Enter the price in dollars:" Input Price Write "Enter state sales...

  • You want to celebrate all of your recent successes. You decide to reward yourself and a special someone with a vacation...

    You want to celebrate all of your recent successes. You decide to reward yourself and a special someone with a vacation to a destination of your choosing. For your trip you will need to stay in a hotel/resort and rent a car. You decide to rent a car for the duration of your trip. You have two options. Write an equation for each company that depicts the total cost of the rental, y, based on the number of days, x....

  • You want to celebrate all of your recent successes. You decide to reward yourself and a special someone with a vacation...

    You want to celebrate all of your recent successes. You decide to reward yourself and a special someone with a vacation to a destination of your choosing. For your trip you will need to stay in a hotel/resort and rent a car. You decide to rent a car for the duration of your trip. You have two options. Write an equation for each company that depicts the total cost of the rental, y, based on the number of days, x....

  • C# question In this project, you will create your own on-line shopping store in the console...

    C# question In this project, you will create your own on-line shopping store in the console application. You can choose different products to sell in your store (at least 8 products). You will create an product inventory text file. The program will display two options at the beginning of the program, Customer and Manager. Customer: If this is a new customer, the program will let customer to register with their information and assign a unique ID number to the new...

  • Problem 5.19 (Excel Video) You decide to take advantage of the current online dating craze and...

    Problem 5.19 (Excel Video) You decide to take advantage of the current online dating craze and start your own Web site. You know that you have 400 people who will sign up immediately and, through a careful marketing research and analysis, determine that membership can grow by 29 percent in the first two years, 20 percent in year 3, and 18 percent in Year 4. How many members do you expect to have at the end of four years? (Round...

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