C/C++ :: Sort Out Input - Getting Rid Of Chars And Only Using Numbers
Apr 2, 2014
I was supposed to sort out an input, getting rid of chars and only using the numbers. So 5a6g7we87hj9 would become 567879. I might be wrong in some way, but I used
if (scanf("%d", &n) {
printf("
%d", n);
}
else {
printf("
Error);
}
and it sorted correctly.
View 1 Replies
ADVERTISEMENT
Apr 3, 2013
I am having difficulty completing 7th last line below I marked the line with an arrow.
Code:
int main(void) {
int MaxNum, /*number of random nos to generate */
i, /*index */
value,
[Code].....
View 4 Replies
View Related
Nov 6, 2014
i'm trying to fill an array with random numbers and then sort them via bubblesort. it seems to work so far. the problem is, that i seem to get the same numbers for the same input. somehow the randomness isn't working.
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, e, f;
}
[code]....
View 3 Replies
View Related
Feb 19, 2014
Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z); The function should reorder the values pointed to by its arguments so that after the call sort3(&x, &y, &z); the numbers satisfy . Your program should input data and print results using the following format:
Enter three numbers: 4.7 1.4 3.2
The ordered sequence is: 1.4 3.2 4.7
And here is my program: C code - 32 lines - codepad
I am getting a lot of errors when I run it through GCC. I can only use pointers.
View 4 Replies
View Related
May 1, 2014
How to do the problem below using loop?
Input numbers until the user types a 0, then output the product of the non 0 numbers: e
E.g., if the user types 2 4 6 0, the program should output 48
View 3 Replies
View Related
Apr 7, 2013
I cannot get this program from having a continuous loop. I need to have a user-defined loop.
Here is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a,b,c,high,med,low;
[Code] ....
View 7 Replies
View Related
Sep 28, 2014
How do i sort numbers from highest to lowest using qsort? I dont have a code. I dont know how to use this one.
View 1 Replies
View Related
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
Oct 7, 2014
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
const int s = 12, p = 6;
int x[s][p];
[Code] ....
Names: P1 P2 P3 P4 P5 P6 AVER.
EVIKE 41 85 72 38 80 69 64.17
KKASV 65 68 96 22 49 67 71.86
YCXFX 51 61 63 87 66 24 70.64
FADPO 80 83 71 60 64 52 80.11
OEJUV 90 60 49 31 23 99 72.02
POEYL 94 11 25 24 51 15 48.67
VRVIP 13 39 67 97 19 76 59.94
QNQRQ 12 33 99 18 92 35 58.16
OOVAO 74 0 95 71 39 33 61.69
NCBXC 39 32 37 45 57 71 57.12
ATXDK 95 5 71 24 86 8 57.69
IXJSW 51 54 74 24 75 70 67.61
AVER. 58.75 49.15 72.35 51.11 62.68 56.81
1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice: 2
Names: P1 P2 P3 P4 P5 P6 AVER.
XXZRZ 41 72 38 80 69 65 60.83
OKETL 68 85 22 49 67 51 67.14
GZQRC 61 63 87 66 24 80 74.69
OJWAY 83 71 60 64 52 90 82.45
PSAJL 60 49 31 23 96 94 72.57
AOVLZ 11 25 24 51 15 13 35.26
CPWSR 39 67 97 19 76 12 57.54
IZCOB 33 99 18 92 35 74 68.09
IJTVD 0 95 71 39 33 39 57.52
LDVGY 32 37 45 57 71 95 65.75
MBORX 5 71 24 86 8 51 51.79
XOHGM 54 74 24 75 70 0 58.13
AVER. 40.58 70.72 50.98 62.66 56.56 60.05
1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice:
Why my sort is not working. Also, I want to keep the same random numbers for the continuation of the program, I don't want new randomized values when I display the table.
View 4 Replies
View Related
Feb 17, 2013
Question: What is the efficiency and big O of the selection sort algorithm when the input happens to already be in nondecreasing order?
Answer: Not sure... since the input is in nondecreasing order, such that example 0, 1, 1, 2, 3, 4, 4, 5 then there will be no swap, Just comparisons of emelemts. So it is big O of n
View 2 Replies
View Related
Jun 28, 2012
I am trying to sort an array of random numbers by passing it to a method Sort(), sort the array, and then pass the entire array back to the calling program. Each time I run this though, the array doesn't seem to sort. I'm not sure if the problem lies with my sorting algorithm or if it has something to do with calling the function.
Code:
static void HighAverage(int[] a) {
for (int i = 0; i < a.Length; i++) {
if ((i + 1) % 10 == 0 && i != 0)
[Code].....
View 5 Replies
View Related
Apr 10, 2013
Whenever I try to call merge sort on large numbers say n=10000000. It gives an error. It works fine for small numbers, even though I have declared my Lists on the heap.
The below code is just the divde part.
List<long>* Merge(List<long> *ParentList) {
if((ParentList)->Length==1) {
return ParentList;
[Code] .....
View 1 Replies
View Related
Jul 15, 2014
I'm still fairly new to c++ and am having trouble with dynamic arrays. My task is to create an array for test scores. The user needs to define the size of the array and then input data to later sort and calculate the average.
Below is what I have so far. I am struggling with the user input part. I receive the following errors for the data input of the individual scores:
"error C2108:subscript is not of integral type"
"IntelliSense:expression must have integral or unscoped enum type"
Code :
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
//user input total number of scores
cout<<"Please enter the total number of test scores."<<endl<<endl;
[Code] ....
View 1 Replies
View Related
Apr 5, 2013
C++ sort algorithm or library that can take input of a bunch of rows of data and then sort rows by an arbitrary defined order of one of the columns ... i.e., sort rows by value of the first column in this order (boba bobc bobe bobx) etc?
View 1 Replies
View Related
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
Apr 6, 2014
My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.
void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */
void printFrequencies( const int list[], int size );
int main (void) {
int status = EXIT_SUCCESS; /* defaulting status to success. */
FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */
[Code] .....
View 6 Replies
View Related
Aug 19, 2013
Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.
Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;
[Code]....
View 9 Replies
View Related
Jan 11, 2015
Program is about to compare any two numbers input. Then, it will display whether the number is minimum or maximum. Use switch statement.
#include <iostream>
using namespace std;
void main() {
int num1, num2;
cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;
[Code] .....
View 4 Replies
View Related
Dec 12, 2014
I want to input only 4(numbers)from a .txt file like Number of Plants: 4 Now where I have to change for this.
#include<iostream>
#include<fstream>
using namespace std;
int main (void) {
ifstream inputFile;
inputFile.open("flp.txt");
if(inputFile.is_open())
[Code]...
View 10 Replies
View Related
May 20, 2013
I'm looking for a algorithm to search portions of string that have the same caracter. The only possible values are: a,n and g
Char index: 0 1 2 3 4 5 6 7 8 9 RESULT
------------------------------------------
Example 1: a g g g a a 0,4
Example 2: g g g a n n a 0,3
Example 3: a g g g g g g a 0,7
Example 4: g g g g g g g 0,6
Example 5: g g a a g a a a g 0,2,3,5,7,8
View 4 Replies
View Related
Jan 26, 2014
Now i got here a program that asks the user to input 2 numbers if the first inputed number is smaller than the second then show all even numbers from the range of the 1st inputed number till the 2nd inputed number, but if the first inputed number is greater than the second then display all odd numbers from the range of the 1st number till the 2nd.
now my question is how do i invert the odd numbers?(on the 2nd condition)
Code:
#include<stdio.h>
int main(void) {
int i,a,b,x;
printf("Enter two numbers");
printf("
First number:");
[Code] ......
View 4 Replies
View Related
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
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
Sep 23, 2014
This is for homework . Must use only getchar and putchar
Code:
int main(void) {
int pch; //first
int ch; //second
[Code]....
And it works , but i need to hit ENTER two times when i have 3,5,7... chars to print result.
View 6 Replies
View Related
Apr 13, 2013
I'm working on a homework project, and it requires me to read in a file of chars into an array, and then do stuff with that array.
Anyways, I have the first part written, where I'm just trying to read in my data.txt file, and I thought I had it written well. It compiles, but then it seg faults, and I'm not sure why. I used calloc for the array, but maybe I misused it? Or is it in my EOF statement? I'm still not sure if that's coded correctly. I need to get past this so I can start testing the other parts of my code.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[] ) {
/* Local Declarations*/
int i;
int *ptr;
char tempc;
[Code] .....
View 1 Replies
View Related
Sep 27, 2013
I am trying to convert some chars to UTF-8 strings...
Example:
std::string gethex(char c) {
/* EXAMPLE
if (c == 'é')
return "%c3%a9";
I need a function that converts chars like "á, é, í, ã" to UTF-8 hexadecimal strings...
*/
}
[Code] .....
[URL] .... does it. Choose UTF-8, type some character and click 'Url Encode'.
View 14 Replies
View Related