C++ :: Find GCD Of Array Of Numbers
Aug 25, 2013
I wrote this GCD function to find gcd of an array of numbers . Here is the code:
long long GCD(long long min,int loc,long long b[]) {
for (long long i=min;i>0;i--) {
bool p=0;
for (long long x=0;x<loc;x++) {
if (b[x]%i!=0)
[Code] ....
Its returning wrong answers. When i tried 6 14 it returns 6
View 6 Replies
ADVERTISEMENT
Apr 18, 2014
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");
[Code] .....
View 1 Replies
View Related
Dec 7, 2013
Question: How to find a duplicate numbers and numbers found once in array.
View 7 Replies
View Related
Aug 19, 2013
I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#include <ctype.h>
#include <stdint.h>
//function to set all non-primes to 0
void *zero_multiples(void *threadid);
[Code] .....
View 4 Replies
View Related
Jul 17, 2012
When I run my program it just gives me 'The smallest number is: 2682760' which isn't true obviously.
Code:
#include <iostream>
int main() {
using namespace std;
int x, smallest;
int Array[7] = {7, 5, 10, 13, 3, 15, 54};
x = Array[0];
[Code] .....
View 3 Replies
View Related
Jun 20, 2012
find the average of 10 numbers to an array using function .the array should be controlled by while loop?
#include <iostream.h>
float sum(float x[],int size);
main() {
float a[10];
int n=10;
[Code] .....
View 2 Replies
View Related
Oct 24, 2014
I need to find the smallest number in my 10x8 arraygrid with random numebr filled in it
Here my Code:
#include <iostream>
using namespace std;
int main() {
int total,average,smallest;
int row=0;
int col=0;
[Code] ....
View 2 Replies
View Related
Jun 6, 2014
I have a question regarding finding similar 4 digit numbers in a pool of 120 numbers
Below is an linear single dimension array of 4 digits
There are 120, 4 digit numbers in total
My question is this - How can I code in C - a function that looks through all the 120, 4 digits to find similar numbers
Example - 2095 is similar or matches to - 0950, 5095, 5250, 5269 - i.e having 3 of the digits that are the same in the 4
The code must print out 2095 + all the matched numbers
If the Matched or Similar numbers are less then a certain number n - that number is discarded and the code should go onto the next number
2095095053741884864037233464846523768035
4340520865405306753553226100610753235081
1160346508409698809176715645765520676974
2398509523307591808464215318649140982136
2388015030217584311064844010520796345135
5376565155806436092330366745536969232311
4351519149310340620918615194324744655250
5330634052450976531053882380318069765623
2186677440212394367468519636617536556706
5274239549814534091052060118499521655275
6351091153944834003545212360098053955218
4835406061305276769161885611376776845269
I have written some code below but it is not working ...
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <memory.h>
#include <dos.h>
FILE *fileptr;
FILE *fileptr1;
[Code] ....
View 10 Replies
View Related
May 13, 2014
im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];
[Code]...
View 5 Replies
View Related
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
Jan 20, 2013
write algorith to display first n odd numbers ?
View 8 Replies
View Related
Apr 27, 2013
i have to make a program where a user inputs one number and i have to find the number of a certain amount of number in the program.
for example:
user input: 2349354787839
output: There are two sevens
i know it has the use of loops but i am having trouble finding a way to scan each individual digit in the input to find if it is a seven or not.
View 8 Replies
View Related
Aug 17, 2013
I have the random values down but when I try to assign randValue to another integer I get an error.I want to make an inner loop where I find 5 random number 50 times and print the average of those numbers.
I know I have the bare bones of the below, but without giving me a huge shove in the right direction can I have a poke? I have been programing for three months now. I have noticed when I do simple fun projects I learn more then what my professor assigned to me. The class is over but I want to keep building.C++ starts in one week...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBERS 5
int main(int argc, const char * argv[]) {
float randValue = 0.0;
int i;
[code]....
View 9 Replies
View Related
Oct 17, 2013
I am trying to create a program that lists all prime numbers within a range of two number. Why the below program isn't working?
#include <iostream>
using namespace std;
int main(){
int high_range;
int low_range;
int w;
[Code] .....
View 3 Replies
View Related
Jan 9, 2013
#include<iostream>
#include <cstdlib>
using namespace std;
[Code].....
View 10 Replies
View Related
Jan 26, 2013
i did a code that determine if the number is prime or not, and i have to do a one that finding the prime numbers between two variables .
the first code:
#include<iostream>
using namespace std;
int main(){
[Code].....
View 4 Replies
View Related
Aug 25, 2013
if i have two integers, say number1 and number2, stored in arrays where each index is a digit of the number (i.e. if my numbers are 321 and 158, then number1 = {3,2,1} and number2 = {1,5,8}), can i find the remainder of number1/number2? assume number1 > number2.
View 1 Replies
View Related
Nov 28, 2013
How to find the smallest number amongst 4 numbers
View 10 Replies
View Related
Oct 23, 2014
I'm trying to find the second smallest number out of 4 numbers. I produced some code that does that but it doesn't work if i have duplicate numbers.
secondSmallest = a;
if(b > secondSmallest) {
secondSmallest = b;
}
if(c < secondSmallest) {
[Code] ....
View 1 Replies
View Related
Apr 27, 2015
I made a program that is suppose to receive 20 numbers or less and find the average, then show all numbers entered but my average does not show. It shows as 0 and a line pops up after every number returned. I am stuck and dont know how to fix the logical errors.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float num[20];
int amount_num;
[Code] ....
View 3 Replies
View Related
Oct 21, 2014
how i solve this..?
View 1 Replies
View Related
Jan 25, 2014
I'm new to C++ and I'm trying to solve the question but there is just something wrong somewhere.
#include <iostream>
using namespace std;
int main() {
int largest;
int a;
int b;
int c;
cout<< "Enter first value";
[Code] ....
View 1 Replies
View Related
Oct 4, 2013
I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.
input file text (first number is num of auctions, after that it's num of bids, then the bids):
5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23
Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!
The silent auction raised $2470.00 for charity!
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
[Code].....
View 4 Replies
View Related
Mar 6, 2015
Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)
Here is the code:
Code:
#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}
int positive(int x) {
return x>0;
[Code]...
My question is how to write this code if the prototype of function is:
Code: void series(int *array, int n, int (*s)(int), int **begining, int *lenght);
View 1 Replies
View Related
Jan 17, 2013
1): write program to c++ to read three numbers from keyboard and find the average of the three numbers?
2): write program c++ to read two numbers from keyboard and swap between numbers like x=4; y=6; the result x=6; y=4;?
I think that int can do that job. but im not sure.
3): must be the result of positive example: (x+(-y)=z)?
with abs ?
4): values for each of : X= ;y= ;z= ;
View 7 Replies
View Related
Dec 23, 2014
I had to write a program to find all the primes between 1 and 100 using the sieve of Eratosthenes so I wrote this program :
#include <iostream>
#include <vector>
using namespace std;
// find all the primes number using Eratosthenes
int main() {
vector<bool> numbers(101);
[Code] .....
My problem is that if I try to modify the program to find all the primes between 1 and max (setting the size of the vector uqual to max) my program becomes slower and I would like to listen by other people some possible solution to don't use vector in this program, the author hasn't shown me yet how to delete a value from a vector so I just used this method to solve the problem.
View 3 Replies
View Related