I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:
1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.
2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.
Here is my code:
Code:
// ConsoleApplication3.cpp : Defines the entry point for the console application.// #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int a[10], i, n; int pom; do { printf("number of elements in an array a: n = ");
I've recently started creating a bingo caller application. I need in changing numbers to different text boxes. When a number is called it will be displayed in a text box and the last four numbers previous to that. However the oldest number needs to delete and for the remening numbers to move when a new number is called.
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.
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;
Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas.
So, if the user enters the values 10 4 6, the output should be 4, 6, 10.
If two values are the same, they should just be ordered together.
So, the input 4 5 4 should give 4, 4, 5.
Code: #include "std_lib_facilities.h" int main() { cout << "Enter three integers, separated by space: "; int a, b, c, temp1 = 0, temp2 = 0; cin >> a >> b >> c;
[Code] ....
My first solution has a bug, so here's the corrected solution, written using only features I have learned in the first three chapters:
Code: #include "std_lib_facilities.h" int main() { cout << "Enter three words, separated by space: "; string a, b, c, temp; cin >> a >> b >> c;
I have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.
now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :
Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:
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?
I want to store a very small number - too small for even a long double. However, I don't need the number to be stored very precisely - in fact, all I really need is the order of magnitude of the number. For example, the number 5.205849034425 X 10^-381 can just be stored as an integer of -381 for my purposes. I don't really care about the precision of the 5.205849034425 part.
The reason I get this very small number, is because I am multiplying together thousands of numbers, all of which are around 0.0001 in value. So, one way to do this would be to store all these individual values as simply their order of magnitude (e.g. -4) and then instead of multiplying the numbers, I would just add up their orders of magnitude. However, I am wondering whether there is a way in C++ to do this without me having to change the way I store my data - I still would like to keep the original values if possible.
So if i write a Loop to calculate Prime Numbers in order, is there any way possible for this to happen in a shorter period of time.
The loop that i constructed took about 11hrs on a Win 7 2GB ram machine to calculate about 150,000 primes, could this be done any faster................
1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food 2. Modify Food 3. Delete Food 4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
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.
I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.
My current code is:
Code: #include <iostream> void input(char a[], char b[], int& size_a, int& size_b); void convert(char a[], int size); void reverse(char a[], int size); void add(char a[], char b[], int c[], int size); int main()
I was talking to someone earlier about how to change the value of something from a function, and they said what was needed was to use a ** to change something, and was wondering if I could get a walk - through of what happens. I understand a single pointer well enough, but a pointer through a pointer is kind of confusing to me. Here is a simple example.
Code: #include <stdio.h> #include <stdlib.h> #define SIZE 5 int add(int ** TOP, int * stack);
int *stack = NULL;
[Code] ....
Why is it that when the program prints the address of TOP in main, it is different than the address of TOP in the function? Is it because it is a different instance of TOP because it is in the function? When I put the number on *TOP, and come out of the function back to main, it then says the address of TOP is the number entered into *TOP, and am not sure why. And the **TOP ++ at the end I am thinking it increments malloc by 1, therefore bringing the pointer TOP up to point at the next element, or am I completely off base there?
I use miracle library to work with big numbers. I defined a number for example X with 192 bit. at first X= 0 ;I want to change for example 3 bit of it to 1 randomly.as a example:
assume that X has 10 bit : X=0000000000 random numbers should be : 1000010001 1010100000 1100000100
I want to change the complexity of the code from O(n) to O(1) . So I wanted to eliminate the for loop . But as the sum "s" stores values like (i-1)/2 or (2*n-i+1)/2 so eliminating the loop involves tedious calculation of floor value of each (i-1)/2 or (2*n-i+1)/2 . It became very difficult for me to do so as I might have derived the wrong formula in sums of floors . Need Changing complexity from O(n) to O(1). Is there any other way to reduce the complexity ? If yes ... then how ?
I have this code which previously used the BigInteger library, however now I have GMP installed and I want to use that instead.
I have read the manual but I cannot figure out how to use GMP in this function without getting errors.
Here is the function:
Code: int lucas(long p){ //p is a number in the range of 2 up to 50,000,000, possibly bigger int s = 4; //previously assigned as a big integer int z; //used in the for loop below int M = 2; //previously assigned as a big integer for(z = 1; z < p; z++){ //this accomplishes the same as 2 to the power of p, and is stored in M M *= 2; } M--;
[code]....
I can initialize variables using the gmp library, but when I'm trying to use the mpz_pow_ui() function I get errors because it wants me to use long integers, which are too small for the numbers I want to work with.
I was wondering if there was a possible way to change my c program into an application so that i can send the application to another person and not let the other person have access to my codings?
My reasons for asking this question: For the application i want to send there are secrets that are meant to be unraveled by gameplay but i dont want people to look at the codes and know everything.
If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?
#include <iostream> #include <math.h> #include<iomanip> #include <vector> using namespace std;