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


ADVERTISEMENT

C/C++ :: Print Rows Of Ascending Digits - Delete Other Ones

Dec 14, 2014

That is sequence "aasdf123456785fg87" will be transformed into "aasdf12345678fg". I need to do this task in two variants: at once using getchar and putchar and then with strings. The object is done, but I think it could be done more easier. My codes:

(1)
char flag = 0;
while ((c = getchar()) != '.')
{
if (isdigit(c))

[Code]....

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 :: How To Print Largest Number From 5 Rows

Sep 26, 2013

i want to print Largest number from any 5 rows.Th number printed should be any one of the largest in the five rows of 2d arrays.I have created code for largest number in each row but how to pick and print them randomly?.

Code:

#include<conio.h>
main( )
{
int a,b,c,d,e,x;
int arr[] = {a,b,c,d,e};
int Matrix[5][5] ={ /*Initializing array*/
2,4,3,5,9,
6,8,2,2,10,

[Code]...

View 9 Replies View Related

C/C++ :: Assigning Symbols To Numbers In 2D Array?

Sep 11, 2014

I'm working on a program in C++ that is supposed to read in a file, store the content of the file into a 2D array, assign characters to each of the numbers in the array and store in a char array, and print both of these arrays. It's then supposed to go through the initial array and make sure that each number doesn't differ in value from it's neighboring numbers by more than 1, correct these errors by replacing these numbers with the value of the average of their neighbors, assign characters to this corrected array as it did before, and print both arrays.

The character assignments go as follows:

0=blank
1=.
2=,
3=_
4=!
5=+
6=*
7=#
8=$
9=&

I have the code written that opens the file and loads the array, but where to go from there. To me the obvious, although probably not best, way to do the assignments is to go through the array with a for loop and use a series of if statements to check for the value of the number at each index and assign the appropriate symbol.

Here is the code I have so far:

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int size = 100, i, j;
prog >> size;
int **numArray = new int* [size];

[code].....

View 2 Replies View Related

C++ :: Display Rows Up To N Using Print Array Function

May 25, 2013

the value of C(k,n) are known as the binomial coeficient and can be arranged in triangle that was known as pascal triangle.

i was been asked to create a program that can display rows up to n=9 using print array function.

C(k,n) = C(k-1,n-1) + C(k,n-1)

how should i start?

View 3 Replies View Related

C :: Sorting Array Alphabetically - Print 10 Names In Ascending Or Descending Order

Apr 9, 2014

//Build a program that uses a single-dimension array to store 10 names input by a user.

//After inputting the names, the user should see a menu with two options to sort and print the 10 names in ascending or descending order.

insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char names[10];
char temp[10];
int count,i,j;
int sort;

[Code] .....

View 10 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C++ :: Sorting 3 Numbers By Ascending Orders?

Jan 30, 2015

We've only covered up to Functions and how to use reference variables inside the function parameter.

One of the hw problem that was assigned was to write a void function that takes three parameters( num1, num2, num3) by reference and sorts their values into ascending order, so that num1 has the lowest, num2 the middle value, and num3 the highest value. For example, if user enters: 14, -4, 8, then the output should look like this:

-4
8
14

I've completed the program with a bunch of if/ else if statements but I was wondering if there was a more efficient way to sort the numbers. Bear in mind, we've only covered materials up to functions so I can't use any other new techniques that we haven't cover yet. Here is my code:

// This program will take three int parameters by reference and sorts their value into ascending order
//so that num1 has the lowest value, num2 has the middle value, and num3 has the highest value
#include <iostream>
using namespace std;
// declare function with reference parameter that with sort numbers
void sortNum(int &, int &, int &);
int main ()
{

[Code]....

View 2 Replies View Related

C/C++ :: Put Numbers In Ascending / Descending Order

Nov 9, 2014

I have to put these numbers in ascending and descending order . The interesting point of the function is that sortMe does NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes. I'm not sure why the function is working, even though I called it in main.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void sortMe(int array[], int sortedIndexes[], int size, char mode);
char option;
const int SIZE = 5;

[Code] .....

View 7 Replies View Related

C++ :: Sorting Numbers In Both Ascending And Descending Order?

Sep 7, 2014

What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?

View 3 Replies View Related

C++ :: Sort Ascending Random Numbers - Vectors

Oct 21, 2013

I'm trying to sort random numbers in ascending order and I was wondering how I should go about that.

Here's what I currently have.

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

[Code].....

I'm trying to put our algorithm between the ////'s. We're only allowed to use for loops also. What I currently have is the minimum number finder and the use of temp to find the values. However, it doesn't seem to be working.

View 2 Replies View Related

C++ :: Summing Numbers In Grid Rows

May 1, 2014

I have to make a grid 40 X 40 with random numbers 0-9. I have already done this and it prints out great. My problem is I need to be able to choose a row number and output the sum of the number in that row. Here is what I have so far.

#include <iostream>
using namespace std;
int main(){
int Values[40][40];
int rows, cols;

[Code] ....

View 7 Replies View Related

Visual C++ :: Array Of Numbers Sorted In Ascending Order?

Jan 30, 2015

understand the details of what this function actually do?

View 7 Replies View Related

C++ :: Sorting User Defined Amount Of Random Numbers In Ascending Order

Jan 30, 2013

I want to implement a function into the code below that sorts the user defined amount of random numbers and then sorts them in ascending order.

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;
class IntegerArray {

[Code] ....

View 5 Replies View Related

C++ :: Sorting Array Of Numbers Into Ascending Order - Bubble Sort Keeps Crashing

Oct 29, 2014

I am trying to write a program which will sort an array of numbers into ascending order, here is my code

#include<iostream>
#include<cmath>
using namespace std;
int main(){
int array[]={1, 5, 17, 3, 75, 4, 4, 23, 5, 12, 34, 34, 805, 345, 435, 234, 6, 47, 4, 9, 0, 56, 32, 78};

[Code] .....

This compiles fine but when I run the .exe for the first time an error message comes up saying program has stopped working. If I run the program again without recompiling it seems to work as expected.

View 2 Replies View Related

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 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++ :: 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







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