C :: Have A Program Where It Ask For Three Numbers

Feb 1, 2013

is there anyway to have a program where it ask for three numbers and you shows which which number is the largest and which is the smallest, e.g.

Enter 1st number: 30
Enter 2nd number: 10
Enter 3rd number: 30
Largest = 30
Smallest = 10

View 12 Replies


ADVERTISEMENT

C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30

May 20, 2014

I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.

#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!

[Code]...

View 5 Replies View Related

C/C++ :: Program That From 50 Numbers Displays Only Numbers Less Than 5

Jan 25, 2015

So i have made an array and made a scanf in a for loop so it can store all numbers entered from keyboard in the array but i dont know how to put the numbers that are less than 5 in another array and then print that array out and the lenght of the array.

View 11 Replies View Related

C++ :: Program To Print Sum Of Even And Odd Numbers

Apr 14, 2013

I am writing a program that prints the sum of even and odd numbers and here is my code

#include <iostream>
using namespace std;
const int SENTINEL = -999;

int main() {
int integers = 0;
int even = 0;
int odd = 0;

[Code] ....

Nut now in the output it adds -999 to the odd numbers ....

View 3 Replies View Related

C++ :: Program That Add And Divide Two Numbers

Mar 20, 2013

I'm practicing so I wrote this simple program that suppose to add and divide two numbers. It does that but the result comes out with a 0 at the front and don't know why.

#include<iostream>
using namespace std;
int main()
{
int a ,b;
int result;
a = 0;
b = 0;

[Code]...

View 4 Replies View Related

C/C++ :: Program To Find The Sum Between Two Numbers

Sep 25, 2014

Q)Write a program to find the sum between (2 numbers )

what's the problem here !

#include<stdio.h>
main()
{
int a,b,c;
int sum=0;
for(a=0;b>a<c;a++)
{
printf(" number1=");

[Code]...

View 5 Replies View Related

C :: How To Create A Program That Not Allow Negative Numbers

Sep 2, 2013

I have a homework assignment due that told me for the "input specification" that "n" is an integer greater then 0. How would I put this in and where?

View 1 Replies View Related

C :: Program Seems To Be Crashing At Random Numbers

Mar 3, 2014

When I go to run the Fibonacci function ( fib ), it begins to return incorrect calculations towards the higher numbers, but then seems to correct itself for a little bit, but then does it again and ultimately crashes. And the program seems to be crashing at random numbers. Sometimes the it will make it up to F(55), other times it will only get to F(20).

Also, when I go to run the program on a Linux server, it segfaults, but it doesn't when I just run it on my IDE. the function adds two arrays with individual digits together. It does this to allow the program to add numbers that would exceed the boundaries of INT_MAX.

Here is the header file "Fibonacci.h":

Code:

#ifndef __FIBONACCI_H
#define __FIBONACCI_H
typedef struct HugeInteger
{
// a dynamically allocated array to hold the digits of a huge integer
int *digits;
// the number of digits in the huge integer (approx. equal to array length)
int length;
} HugeInteger;
}

[code]....

View 12 Replies View Related

C++ :: Program That Keeps Generating Two Random Numbers Between 1 And 10

May 6, 2013

#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {

[Code] ....

Write a program that keeps generating two random numbers between 1 and 10 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.

Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.

After presenting the number of pairs of numbers specified and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.

When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.

After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.

Use a nested for loop to display the table; a bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.

The following is a sample interaction between the user and the program:

Enter the number of questions to ask: 5

1. What is 3 x 9? 27
Right!

2. What is 2 x 7? 14
Right!

3. What is 8 x 9? 63
Wrong! 8 x 9 = 72

4. What is 6 x 3? 21
Wrong! 6 x 3 = 18

5. What is 2 x 9? 18
Right!

You got 3 out of 5 right which is 60%.

Play agian? [y/n] n

View 10 Replies View Related

C++ :: Program That Display Prime Numbers From 1 To 100

Oct 4, 2014

This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.

#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()

[Code] ....

View 3 Replies View Related

C++ :: Program To Display First 40 Fibonacci Numbers

Feb 25, 2014

Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:

0, 1, 1, 2, 3, 5, 8, 13, 21,….

Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.

Here is what i have but i get errors!

#include <iostream>
using namespace std; {
int FirstNumber = 0;
int SecondNumber = 1;
int NumberOfNumbers = 2;
int NewNumber;

[Code] .....

View 3 Replies View Related

C++ ::  Error In Prime Numbers Program

Jan 29, 2013

Here is what I have:

#include <iostream>
#include <cmath>

using std::cout;
using std::endl;
using std::cin;

[Code] .....

This is the output after compiling when I enter 10 as 'x':
3
5
5
5
7
7
7
7
7
9

View 1 Replies View Related

C++ :: Program That Prints Out Random Numbers

Nov 1, 2013

output should look like this -

So far i have this

[code]#include <iostream>
#include <time.h>
using namespace std;

int main() {
srand(time(NULL));

[Code] .....

I am getting these errors when i compile it

random.cpp: In function âint main()â:
random.cpp:23: error: expected â,â or â;â before numeric constant
random.cpp:24: error: âRâ was not declared in this scope
random.cpp:25: error: âRâ was not declared in this scope
random.cpp:26: error: âRâ was not declared in this scope
random.cpp:27: error: âRâ was not declared in this scope
random.cpp:28: error: âRâ was not declared in this scope

View 3 Replies View Related

C++ :: Program Must Print Out 5 Random Numbers

Feb 10, 2014

The program must print out 5 random numbers, from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same....

for example

1,2,3,4,5
6,7,8,9,10
....
...
..

here is my code:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
int xRan1;

[Code] ....

View 2 Replies View Related

C++ :: Program To Take Numbers From Input File?

Nov 12, 2013

I am trying to write a C program to take numbers from an input file (input.dat), calculate the sum and average of the numbers for each row, and display them in a form of table and in an output file (result.out).

Using these numbers in the input file.

-0.043200 -0.003471 0.000000
-0.040326 -0.004851 -0.000737
-0.018204 -0.004246 -0.001530
0.022249 0.008891 0.004870
0.074892 0.044237 0.032171
0.129600 0.100233 0.089016
0.174747 0.160100 0.161792
0.200242 0.199106 0.214417
0.174747 0.160100 0.161792

i have created the the file but i keep getting errors in the underlined area after the while!!!

#include <stdio.h>
int
main(void)
{

[Code].....

View 1 Replies View Related

C++ :: Program That Remove 0 From N Typed Numbers

Dec 23, 2014

I`ve made a program that removes "0" from "n" typed numbers now i have to do the same but remove the duplicate here is my program:

#include <iostream>
#include <new>
#include <fstream>
using namespace std;
int main () {
//declaration of variables:

[Code] ...

View 1 Replies View Related

C++ :: Program That Ask The Users To Input 4 Different Numbers

Nov 30, 2013

Make a program that will ask the users to input 4 different numbers. After the user’s input the program will display the formula on the next line. Next line would be the presentation of the formula which the variables were substituted by the inputs from the user, then returns the average of the numbers entered. **All inputs are integers except average which is float with two decimal places.

View 5 Replies View Related

C/C++ :: Lottery Program That Generate 5 Different Numbers Between 1 And 20

Nov 4, 2014

I am a C++ beginner with no programming background. I need to write a lottery program that generate 5 non-duplicate numbers between 1 and 20. Here is my code and it just wont work.

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));
int lottery[5] = { 0, 0, 0, 0, 0 }, count = 0, rand_lottery;

[Code] ....

View 2 Replies View Related

C/C++ :: Program Which Ask For X Numbers And Store Them In Array

Nov 22, 2014

This is in c. Write a program which asks for X numbers, and stores them in an array.

The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number

Make an array of the indexes where the number was found, and then format your output to match my output.

Sample Run:

How many numbers would you like to enter: 5

Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2

The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4

Press any key to continue . . .

View 10 Replies View Related

C++ :: Program That Reads In Ten Whole Numbers And Output Sum

Jan 23, 2014

Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.

Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.

this is what i got but it wont run saying there is an error

#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;

[Code] ....

View 5 Replies View Related

C/C++ :: Two Numbers Relationship Program Error

Aug 15, 2014

I write below two numbers relationship program and got below error.

//two numbers relationship
//take standard and console input and output
#include <stdio.h>
#include <conio.h>
//take function main
main()

//define numbers {
int num1; //first number
int num2; //second number

[Code] ....

View 3 Replies View Related

C/C++ :: Make Program To Square Numbers From 1 To 20

Oct 21, 2012

I want to make program to square the numbers from 1 to 20. i have written this program, it's running but not giving the required answer.i think it is giving a garbage value...

void main(void)
{int a;
  int  b;
b=a*a;
for (a=1; a<21; a++)
{printf("%d",b);
printf("the square is%d=b");
}
getche();}

View 2 Replies View Related

C++ :: Number Sorting Program - Getting Correct Numbers

May 10, 2014

I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

[Code] .....

Input.DAT
Code:
376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421

I can't for the life of me figure out why the numbers are all messed up.

View 5 Replies View Related

C++ :: Program To Play Numbers Guessing Game

Dec 14, 2014

"Write a program to play a numbers guessing game. The user thinks of a number between 1 and 100 and your program asks questions to figure out what the number is (e.g., "Is the number you are thinking of less than 50?"). Your program should be able to identify the number after asking no more than seven questions. Hint: Use < and <= opeartors and the if-else construct."

What I've managed so far, but what I have seems to be lacking

Code:
#include "../../std_lib_facilities.h"

int half(int guess);
int going_up(int i);

int main()

[Code] ....

View 4 Replies View Related

C :: Program To Print All Of Prime Numbers To Screen

May 29, 2013

I'm trying to write a program that prints all of the prime numbers to the screen. I'm getting angry because it only prints EVERY number. I think it has something to do with the bool change not being able to leave the for-loop but how to fix it.

Code:
#import <stdio.h>
#include <stdbool.h>
int main(void){
printf("
The Primes Are: 1");

[Code] ....

View 3 Replies View Related

C :: Program That Sorts Array Of 5 Integer Numbers

Oct 6, 2013

Write a C program that sorts an unsorted array of 5 integer numbers in ascending order by swapping numbers repeatedly. Specifically, first prompt the user to input 5 numbers and store the numbers in an array. Then, if the numbers in the array are not in ascending order, ask the user to provide the indices of two numbers in the array that the user wants to swap. If the user does not enter valid indices (i.e., outside 0 to4), then re-prompt the user to enter new indices. Continue prompting the user to provide indices of numbers to swap until the array becomes sorted in ascending order. Finally, when the array becomes sorted, the program should print "The array is now sorted in ascending order".

Implementation Requirements

Use the #define directive to define the size of the array.

Implement a function called "checkArrayOrder" to check whether an array is in ascending order or not. The prototype of the function is

"intcheckArrayOrder(int arr[], int size);". The function should return

1 if the array passed to the function is in ascending order0 if the array passed to the function is not in ascending order

Define the function prototype in your program.

Implement a function called "swap", whose prototype is "int swap(int arr[], int size, int i, int j);" which swaps the numbers in positions "i" and "j" of the array passed to the function and returns

1 if the indices"i" and "j" are within bounds (i.e., between 0 and 4) and the swap operation is performed correctly.
0 if the indices"i" and "j" are outside bounds so that the swap operation cannot be performed.

Define the function prototype in your program.

Use the function "checkArrayOrder" whenever your program needs to check whether an array is in ascending order or not; and the function "swap" to swap the numbers the user specifies (Note that, you should check whether the user provided indices are valid inside the function "swap" and not inside "main").

here is my code so far

Code:
#define ARRAY_SIZE 5
void main()
{
int i, array[ARRAY_SIZE];

printf("Enter %d numbers
", ARRAY_SIZE);
for(i=0; i<ARRAY_SIZE; ++i)
scanf("%d", &array[i]);

[Code] .....

I'm just not sure how to proceed. I'm not really sure how to progress the checkArrayOrder function to the swap function (in the if statement).

View 7 Replies View Related







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