C :: Find Duplicate Numbers And Numbers Found Once In Array
Dec 7, 2013Question: How to find a duplicate numbers and numbers found once in array.
View 7 RepliesQuestion: How to find a duplicate numbers and numbers found once in array.
View 7 RepliesFind 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] .....
program that generates 5 non duplicate numbers that is between 1 and 20 by using arrays. Here is my code and i cant compile it.
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(NULL));
[Code]...
I'm having issues with writing to a file. more precisely, i'm trying to determine if a set of numbers are in the file. if they are already in it, don't write to the file. if not, write to the file. My problem is my program is writing all numbers, even duplicates. The sort is working.
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
//Counter Stats
int STR;
[code].....
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
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] .....
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] .....
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] .....
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] ....
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] ....
You should implement the following function:
int is_phone_number(char* string)
This function will take in a string and return 1 if it looks like a phone number 0 otherwise. A phone number takes the form (xxx)-xxx-xxxx where the xs are digits 0-9. So for example (123)-456-7890 is a valid phone number while 123 456-7890 is not.
You should also write a main function that parses a text document and prints out all of the phone numbers found. Hint, look up the strtok function.
Sample input:
Please call me at (123)-456-789 sometime tonight.
Sample output:
Phone number : (123)-456-7890
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]...
I have an algorithm which uses nested for loops, which looks for duplicate elements in an array. However, as soon as one duplicate element is found... the program will stop looking for more duplicates? My program continues to look for more even though one is found? I know there is a break command but I can't get it to work. Code is below:
output of program: Repeating element found first was: 2, 1
Although I want the outcome to be; Repeating element found first was: 2
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
void printRepeating(int arr[], int size) {
int i, j;
[Code] .....
The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:
1 3 4 5 6 8 10 13 14 16 17 18 19 20 25
3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________
Count = 8, in this case..
I think it's not very difficult to do, but i just can't see how to do it.
#include <iostream>
#include <vector>
#include <numeric>
[Code]....
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]...
write algorith to display first n odd numbers ?
View 8 Replies View Relatedi 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.
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]....
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] .....
#include<iostream>
#include <cstdlib>
using namespace std;
[Code].....
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].....
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 RelatedHow to find the smallest number amongst 4 numbers
View 10 Replies View RelatedI'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] ....
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] ....
how i solve this..?
View 1 Replies View Related