C :: Won't Print Numbers Sorted When Use Print Function

Nov 17, 2013

I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort

Code:

void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}

[code]....

put it wont print the numbers sorted when I use my print function, just the unsorted numbers.

View 1 Replies


ADVERTISEMENT

C++ :: Function To Determine And Print Prime Numbers

Mar 30, 2013

/* Task: create a function that determines prime number and use it to print out prime numbers from 0-50: */

Function prototype: Should return a `bool` (because it answers a yes/no question) and should take in a single int (to ask whether it's prime).

- An int greater than 2 is prime if it is not divisible by any number between 2 and itself, not including itself.
- Use this function to print out the primes less than 50. Check it against my list:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

#include <iostream>
using namespace std;
int prime(int&x) {
if(x%2==1)

[Code] ....

It is printing out the correct prime numbers but also printing this between each number: 1629974960

View 3 Replies View Related

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++ :: Print All The Whole Numbers From 1 To N

Feb 17, 2012

I did write a print function which the user put a number and then it will print out till that number

the output is correct ,, but is code correct ? or it could be better somehow ?

write a function named print_out that print all the whole numbers from 1 to n. test the function by placing it in a program that passes a number n to print_out , where this number is entered from the keyboard . the print_out function should have type void; it does not return a value. the function can be called with a simple statement:

print_out(n);

PHP Code:

# include <iostream>
using namespace std;
void print_out (int x);
int main () {
    int n;
    cout << " enter a number : ";

[Code] ....

View 2 Replies View Related

C/C++ :: Using Print Statement To Print Certain Number Of Spaces

Sep 1, 2014

is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?

for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}

This is suppose to output

t=-3 *
t=-2 *
t=-1
.
.
.

View 2 Replies View Related

C++ :: N Prime Numbers - Print Out And Sum

Mar 3, 2014

Write a c++ program to print out the first n prime numbers and the sum of the first n prime numbers.

View 7 Replies View Related

C++ :: Print All 64-bit Binary Numbers

Jul 31, 2013

I have a program in c++ to print all the binary numbers that have 64 bits. But the problem is it works only for 30 bits. Beyond that the program does not work possibly because of insufficient space availability.

my code is as below:

// C++ program to generate n-bit binary numbers
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

// This function generates all n bit Gray codes and prints the generated codes
void generateSequence(int n)

[Code] ....

View 2 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++ :: While Loops To Print Even Numbers?

Feb 12, 2012

i am trying to write a program to get a number from user and then print even numbers as well as 0,2,4 and so on.what changes i should do ?

PHP Code:

# include <iostream>
using namespace std;
int main () { 
    int n,i;
    cout << " Enter number ";
    cin >>n;
    i = 0;
    while ( i%2 == n) {
        cout <<i<<" ";
        i = i+1;
    } system ("PAUSE");
    return 0;

View 13 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++ :: Insert 10 Different Numbers To BST And Print Out Randomly?

Jul 1, 2014

How to insert 10 different numbers to a BST and print out randomly?

View 2 Replies View Related

C++ :: Print Prime Numbers - Vectors

Jan 25, 2015

I am trying to print the prime numbers, so i put the numbers into the vector and then erase the non prime numbers. if i comment the break statement i get runtime error saying out of bound, but if i don't comment it out it prints the primes but it also prints the multiples of 3.

void Eratos( int length, vector< int > &v ) {
int i;
for (i=0; i<length; ++i) {
v.push_back(i);
cout <<v[i];

[Code] ....

View 3 Replies View Related

Visual C++ :: Print Dash After Every 3 Numbers From ID

Dec 7, 2013

I am currently working on a student records program and I want it to print a '-' after every 3 digits from the Id number that I read from the file(ID number from file doesn't have the dashes). How would I do that to print it with dashes?

Here are my reading functions.

Code:
void Read_Student(Student & Temp , ifstream & fin){

fin >> Temp.FirstName;
fin >> Temp.LastName;
fin >> Temp.Id;
fin >> Temp.Quiz;
for (int i = 0 ; i < 6 ; i++)
fin >> Temp.Test[i];

[Code] ....

Intro To Computer Science C++
SAL 343
JHG 344
John Adams
111223333 100 87 93 90 90 89 91
Willy Smith
222114444 90 73 67 -77 70 80 90
Phil Jordan
777886666 100 80 70 -50 60 90 100

One more thing, I also am having problems with reading last name. If I edited the inout file and had for example John Adams Jr. it would cause huge print problems. When I remove it it prints out perfectly.

View 9 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 :: Print All Numbers Up To The Inputted Number Vertically

Feb 19, 2013

I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as
1
2
3

no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints

1 2 3 4 5 6 7 8 9 1 1
0 1

i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.

View 3 Replies View Related

C :: Print All Combinations Of Numbers That Can Compose A Given Number

Mar 6, 2015

Coding for- To print all combinations of numbers that can compose a given number..

View 3 Replies View Related

C++ :: Find And Print Average Of Odd Numbers Greater Than 5 And Less Than 100

Nov 5, 2014

I am new to programming in C++, and have got a project on this.

Write a C++ program that accepts three numbers from the user (All are integers):

Such as:

Enter the first mark: 3
Enter the second mark: 25
Enter the third mark: 23

The program should find and print the average of the odd numbers greater than 5 and less than 100.

View 4 Replies View Related

C/C++ :: Print Rows Of Ascending Numbers And Other Symbols?

Dec 16, 2014

for example having input "12345556asf87" we get "123456asf". I need to do this task with getchar and putchar, and the with strings. My programs aren't working

stream:
char c = 0, c_ = 0;
char flag = 0;
while ((c = getchar()) != '.')
{

[Code]....

View 1 Replies View Related

C/C++ :: Print Binary Numbers From 0 To M - Size N Bits

Apr 26, 2014

I need writing a program that print binary numbers from 0 to M.

Size N bits.

Ascending or descending order according to user choice.

When the default is M = 8, N = 3

View 5 Replies View Related

C++ :: Print Numbers At Random From A Set Using Single Statement

Jan 21, 2012

I have an exercise that asks me to print numbers at random from the following set (using only a single statement):

2, 4, 6, 8, 10

Here's my statement:

Code:
cout << (2 + rand() % 9) << " ";

which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?

View 10 Replies View Related

C :: Print Listing With Line Numbers - Cannot Execute / Run Program

Feb 18, 2013

The problem is with the first "Type and Run," where the code looks like this:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] ....

I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:

Code:
print_it.c: In function "main":
print_it.c:36:15: error: "stdprn" undeclared (first use in this function)
print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in
print_it.c: In function "do_heading":
print_it.c:49:16: error: "stdprn" undeclared (first use in this function)

I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:

Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);
int line = 0, page = 0;

[Code] .....

It compiled OK with the gcc compiler but I only get this when I run the program:

Code:
Proper Usage is:
print_it filename.ext

I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.

Questions:

1. What should be done to make this program run?
2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?

View 6 Replies View Related

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++ :: Print Square Roots Of Numbers With Rows And Columns

Mar 12, 2013

this is what i have so far

#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;

[Code] ....

im trying to get the program to print this as an example if the user enters 5 (the rounding of the decimal is optional).

1 1.41 1.73 2 2.24
1 1.41 1.73 2
1 1.41 1.73
1 1.41
1

why its not reading my for loop for rows its only doing columns ...

View 4 Replies View Related

C++ :: 3 Integer Numbers - Find And Print Mean / Maximum And Second Minimum

Oct 25, 2014

The question is: Write a program that reads 3 integer numbers, then finds and prints the: Mean - Maximum & Second Minimum.

#include <iostream>
using namespace std;
int main () {
double a, b, c;
cout<< "Please enter three values"<<endl;

[Code] .....

View 6 Replies View Related

C++ :: Pass Array Of Int And Its Size - Print Out Numbers Above Average

Nov 15, 2013

I am attempting to write a program " that has a function that is passed an array of int and its size, and with that it prints out only the numbers that are above average. "

I have included my code so far, but I am only getting one value as output, and that value seems to be completely off. I keep trying, but I am really stuck.

#include <iostream>
using namespace std;
int average(int values[],int size);
int main(){
int size;
int values[] = {1,2,3,4,5,6};

[Code] ....

Added the floats in the average() function. But there is still a value problem.

View 1 Replies View Related

C/C++ :: Program That Will Print Numbers In Columns From User Input

Oct 7, 2014

I tried to work on this program for while, but I am not able to get it to work

Directions:Write a program that reads an integer n from the user.

Display the first 100 numbers, with newlines every n numbers, using % operator

#include <stdio.h>
int main(void){
int a = 0;
int b = 99;
printf("Enter a number: ");
scanf ("%d", &a);

[Code] ....

When I run this code it asks me to enter a number. It doesn't matter what number I enter it gives me the numbers from 1 to 100 in one horizontal line.

I want this program to do something like this:

for example if the user enters n=6 the program should give:

0 1 2 3 4 5 6
7 8 9 10 11 12 13
and so on

View 2 Replies View Related







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