C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies


ADVERTISEMENT

C++ :: Program Which Print Out All Prime Numbers Less Than Or Equal To Given Number

Nov 11, 2013

how to make a programm in native c++ which print out all prime numbers less than or equal to given number????????

View 5 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C++ :: Receive Number From User And Output Largest Prime Number

Nov 20, 2014

I am attempting to write code that receives a number from the user and outputs the largest prime number underneath the user's number. There are no errors in my code, but no matter what number is imputed, the program says the largest prime number is 1. I cannot find where the issue is in the code. Here is the code I wrote:

#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num);//function prototype

[Code] ....

View 2 Replies View Related

C++ :: Write Program Which Tells User If Number They Input Is Prime Or Not?

May 2, 2014

So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.

#include <cstdlib>
#include <iostream>
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Write Program That Prompts User To Enter Item Number

Jun 27, 2013

Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.

All I have so far is

string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;

I need to finish the rest in pseudo code

View 2 Replies View Related

C/C++ :: Creating Program That Allows User To Enter Unknown Number Of Income / Expense Amounts

Feb 21, 2014

I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.

#include <iostream>
using namespace std;
int main() {
//declare variables
double incomeInput;
double expenseInput;
double incomeTotal=0;
double expenseTotal=0;

[code]....

View 5 Replies View Related

C++ :: Prime Number Program Not Working With Odd Non-prime Numbers

Dec 2, 2014

I have a program that gets prime numbers that doesn't work. It looks like it works for all prime numbers except odd non-prime ones. Here is the code:

Code:
#include <iostream>
using namespace std;
bool isPrime(int prime) {
while(true) {
int track = 0;

[Code] ...

View 3 Replies View Related

C++ :: Determines Whether A Number Which User Inputs Is Prime Or Not

Jan 11, 2015

I am fairly new to C++ and I am trying to write a code that determines whether a number which the user inputs is prime or not. I have the code, but when I run it all it actually does is report odd numbers as prime and even numbers as not prime.

#include <iostream>
using namespace std;
//declaring variables//
int i;
int num;

[Code] ....

View 7 Replies View Related

C/C++ :: User Input - Number Prime Or Composite?

Mar 8, 2014

User will input a number in the range of 2 and 2^63-1 and the program will decide whether it's prime or not by a simple 'YES' or 'NO'.

I figured out a code:

#include <stdio.h>
#include <string.h>
main() {
unsigned long long n,i=3; int temp=0;
int t;
scanf("%d",&t); //Number of test cases

[Code] ....

Now this code works for normal inputs but whenever I try it with large primes in tat range, like 987654321987654329 or 9223372036854775783 it does not work />.

I tried to print the values of i to check the limit to which it runs.. and I found it 23697, whose square is 561547809 - nowhere near about the input primes.

View 10 Replies View Related

C++ :: How To Restrict User To Enter Four Digit Number Only

Aug 22, 2014

I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.

I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.

int number;
cout<<("Please enter the four digit number(Ex: 0001):
");
cin>> setw(2) >> number;
cout<<)"Please enter four digit date. Two digits for month and two digits for year:
");
cin>> date;
if (number< || number > 30)
cout << "Invalid choice. Try again." << endl;
cin.clear();

View 2 Replies View Related

C/C++ :: Find Prime Factors Of Number Input By User?

Apr 21, 2014

find the prime factors of the number input by the user. This time, we are going to have the user input a number, and the program will find all prime numbers from 2 to that number and prime factors of the number input by the user

#include <iostream>
#include <cmath>
using namespace std;

[Code]......

View 5 Replies View Related

C++ :: Basic Calculator - User Will Have To Press Enter After Every Number

Mar 22, 2013

I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?

#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();

[Code] .....

View 6 Replies View Related

C/C++ :: How To Ask A User To Enter Date And ISBN Number In Specific Format

Dec 4, 2014

I don't know how to ask the user to enter the date in this format (DD/MM/YY) and ISBN number with hyphens.

After user enter date and ISBN number, it should look like this:

Date: 5/24/12
ISBN: 0-000-12345-0
#include <iostream>
#include <string>
using namespace std;
int main() {
string date;//MM/DD/YY Format

[Code] ....

View 7 Replies View Related

C :: Write A Code To Find All The Prime Numbers Before A User Entered Number

Apr 9, 2014

I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.

Code:

#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */

[Code]...

It says the error is on line 23

View 6 Replies View Related

C/C++ :: Program To Check Number Is Prime Or Not

Jan 12, 2013

What is the minimum range of numbers which we need to go necessarily to check either a number is prime or not?(for all integers) ....

View 6 Replies View Related

C++ :: Program To Tell Whether Number Is Prime Or Not - Illegal Structure Operation

Mar 2, 2013

In 83rd line message says: "Illegal Structure operation". But I didn't use any structures! How to correct it?

#include<iostream.h>
#include<conio.h>
#include<math.h>
int prime(int);
int reverse(int) ;
int power(int,int);
int rectangle(int,int);
int square(int);
int circle(int);
void tables(int);

[Code] ....

View 6 Replies View Related

C++ :: Enter Decimal Number Into Program And Required Base

Oct 12, 2013

You enter decimal number into the program and what base you want. The integer part of the decimal is being handled fine, but the decimal is not.

For example, I enter 15.6847 and base 10, which means I'm going from base 10 to base 10. It spits out 68469999999999 for the decimal part. (Do not worry about the first block of numbers. The second block seperated from the first by a space is where the decimal will appear in order.)

#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int baseConverter(int, int, int *, int *);

[Code] ....

View 2 Replies View Related

C :: Take User Input Between 1 And 10 And Print Out Number As A Word

Oct 2, 2014

I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.Here's what I've got so far:

Code:
#include <stdio.h>
int name(int n);
char numberOne[] = "One";
int main(void)
{
int n;
}

[code]...

However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result.

View 6 Replies View Related

C/C++ :: Finding All Prime Numbers To Nth Prime Number

Aug 24, 2014

I'm a new coder for C++, and I've recently learned java before starting this programming language. I'm attempting to find all prime numbers up to the number a user enters (i.e. User enters 10, System shows "1,2,3,5,7"),

#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char** argv) {
int num;
cout << "Enter a positive number." << endl;

[Code] ....

I've been looking at my forloop, and I can't seem to pinpoint the problem with it.

View 1 Replies View Related

C/C++ :: Program To Print Out Binary Value Of 16 Bit Number

Sep 22, 2013

Write a program to print out the binary value of a 16 bit number.

Create integers i, count, and mask.

Set 'i' to a hex value of 0x1b53.

Set mask to a value of 0x8000. Why?

print a line to show the hex value of i and then the leader for the binary value like this: Hex value = 1b53 Binary=

Use a for loop to loop 16 times and print 16 digits, using count as the loop counter

To test for each digit value, bitwise and 'i' with 'mask'

when the result for the bitwise and is true, print the number '1'

when the result for the bitwise and is false, print the number '0'

then shift mask one place to the right

print a new line and then quit

Use prtscrn and make a hard copy of the code with the console output.

Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read

The output should look like this: Hex value = 1b53, Binary= 0001 1011 0101 0011

so far this is what i have

#include <stdio.h>
#include <stdlib.h>  
int main() {
    int i, count, mask;
    //   1B53  0001 1011 0101 0011
    //   8000  1000 0000 0000 0000
    i = 0x1b53;

[Code] ....

it is telling me that there is an "else" without previous "if", also is the program that I wrote correct?

View 3 Replies View Related

C++ :: Print Out Number Of Twin Primes Program

Jul 27, 2014

This program prints out the total number of up to 100,000. How to do is to print out the number of twin primes up to 100,000. Is it as simple as adding an if statement "if(primesList[j] - i == 2)"?

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
int primesCount = 0;

[Code] ......

View 4 Replies View Related

C/C++ :: Program To Scan Number And String Then Print Them To A File

Mar 19, 2015

I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :

1 test
2 dream
3 code

then output (in data.list file) would be:

1 test
2 dream
3 code
3 code

I also changed the program code so that it reads from data.list file. even here it duplicates last line!

so when program reads the info above saved in data.list it would be:

1 test
2 dream
3 code
3 code
3 code

here's the code for writing:

#include <stdio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;
fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist
while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X

[Code]...

and the one for reading from file:

#include <stdio.h>
#include <conio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;

[Code]...

How do I fix this behavior??

View 3 Replies View Related

C :: How To Reserved Int Number And Print As Float Number

Nov 24, 2013

How to reserved int number and print as float number ?

View 1 Replies View Related

C/C++ :: Program That Read A Number From Keyboard And Print Separated Digits To Screen

Feb 18, 2015

Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.

For example, if the number is 2339 the program should print

9 *********
3 ***
3 ***
2 **

So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!

My code so far:

int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d

[Code]...

View 4 Replies View Related

C/C++ :: Program To Read Sequence Of N Integers And Print Number With Maximum Occurrence

Mar 24, 2014

write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved