C/C++ :: Finding First Non-repeated Digit In Array

Aug 26, 2014

With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".

This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0.
nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....

for (n=0; n<sizeof(digits)/sizeof(int); n++) {
if(repCount<2) {
// nonRepCount=0;
for (o=n+1; o<sizeof(digits)/sizeof(int); o++)

[Code] .....

View 1 Replies


ADVERTISEMENT

C++ :: Repeated Digit In Integer

Oct 19, 2013

this code :

#include <cstdlib>
#include <iostream>
#define TRUE 1
#define FALSE 0
using namespace std;
typedef int Bool;

[Code] ....

Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.

so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????

View 3 Replies View Related

C++ :: Print Repeated Array Of 2D?

Mar 23, 2014

Printing duplicate 2D array elements

if for 1D array

for (int i = 0; i<0; i++){
for (int j = i+1; j<0; i++)
{
if (arra[i] == arra[j]){
cout<<arra[i]<<endl
}
}
}

how would i do for 2D

View 5 Replies View Related

C++ :: How To Count Repeated Numbers In Array

Jan 30, 2015

So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int inputs[30];
int numofloops;
int maxvalue = inputs[0];

[Code]...

View 1 Replies View Related

C :: Replace Repeated Elements Within 2D (10x10) Int Array

Mar 20, 2014

I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.

Code:
46 for(row=0;row<10;row++)
47 {
48 for(col=0;col<10;col++)
49 {
50 board[row][col]=rand()%4+1; //filling matrix here

[Code] .....

I know there must exist a much more elegant approach than listing out all permutations.

View 1 Replies View Related

C/C++ :: Swap A Digit From A Number With Another Digit Using Function

Oct 26, 2014

Write a function which will take 3 arguments. The function needs to return a new number which is formed by replacing the digit on a given position in the number with a digit which is carried as an argument (the position in the number is counted from right to left, starting with one). Write a main program which will print the newly formed number.

Examples:
A function call of 2376, 3 and 5 should return the number 2576
A function call of 123456, 4 and 9 should return the number 129456

What I succeeded to do so far:
Figure out the logic for swapping the digit and write working code for it (in the main function).

What I failed to do so far:
Write a function which will return the desired result.

What is my problem:
I tried writing a function to do this, but as you see from my calculations, my result is divided in 3 parts. I don't know how to return more variables from a function.

Code:

#include <stdio.h>
int main() {
int inputNumber, swapPosition, swapDigit;
scanf("%d%d%d", &inputNumber, &swapPosition, &swapDigit);
int i, numberPart1 = inputNumber;
for (i = 1; i <= swapPosition; i++)

[Code] ...

View 8 Replies View Related

C :: How To Get Each Digit Of A Number From Array

Apr 14, 2013

I have an array join[], some of its elements are single digit and some are numbers. I want to print the output in single digit form.Like in below code

Code:
int join[3]= {12,0,3};
int split;
int j;
for (j=0;j<3; j++) {

[Code] ....

My code won't consider array element "0". How can i fix it for that too.

Code: I want output should be like
1
2
0
3

View 4 Replies View Related

C++ :: How To Save Two Digit Variables In Array

Feb 11, 2014

I am trying to redefine an array, but the result can only display one digit variable. I want the program to display 97 98 99 *+, but the program is only displaying 789*+.

int main() {
string test="abc*+";
for(int i=0; i<test.size;i++)

[Code].....

View 1 Replies View Related

C++ :: Heap And Priority Queue (Array Not Storing Digit)

Feb 27, 2015

This assignment is about Heap and PQ's to sort out jobs inside a printer. I'm far from finishing the assignment but the most important part isn't working. My issue is that nothing is getting stored inside the array. I keep getting crashes and at this point I'm not sure what to do. I notice that my destructor runs right after my "addJob" Function finishes, which is destroying the memory. Which might be why nothing gets stored inside OR I think my implementation of Heap/PQ is wrong.

Functions inside my test.cpp aren't properly done, they are made just to see if something is stored inside.

1. Check if I created the array correctly [PQtype.cpp / Heap.h/ PQType.h]
2. Am I even using/storing into the array. [Test.cpp "addJob" Function]
3. I'm also new to working with Class Templates.

PQType.h
template<class ItemType>
class PQType {
public:
PQType(int);
PQType(const PQType&); /

[Code] .....

View 4 Replies View Related

C++ :: Program To Display All Fibonacci Numbers And 21st Digit Using Array

Mar 7, 2013

Create a program that display all the fibonacci numbers and display the 21st digit using array.

Here's my code:

#include <iostream>
using namespace std;
int main () {
cout<<" This program shows a series of fibonacci numbers
"<<endl;

[Code] ....

View 2 Replies View Related

C++ :: Game Of Pick 4 - How To Find Similar 4 Digit Numbers In Array Of 120

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

C++ :: Convert To Int Part Of 1000 Digit Long Number Defined In Char Array

Jan 28, 2015

How do I convert just the number from position 4 to 15 from this char array and convert to int and save to variable

char numbers[]="54155444546546545643246543241465432165456";

the real char got 1000 digits this is just example how do i convert chars from numbers[4] to numbers[15] and save them as one number ? in this case i will get int x = 5444546546545643 as u can see char numbers as a example above

View 4 Replies View Related

C++ :: Finding A Value In 2D Array?

Jul 9, 2014

I want to search a 2D array to see if it contains a certain value x. I can come up with three different ways to do this. Provided I have:

const int Rows = 40;
const int Columns = 30;
int SampleData[Rows][Columns] = { ... }

Is there any real difference (in terms of performance etc.) between these, or are there an even better solution?

Solution 1:
for(unsigned row = 0; row < Rows; ++row) {
for(unsigned col = 0; col < Columns; ++col) {
if(SampleData[row][col] == x) {
// found
} } }

Solution 2:
int* data = &SampleData[0][0];
if(find(data, data + Rows * Columns, x) != data + Rows * Columns) {
// found
}

Solution 3:
int* data = &SampleData[0][0];
for(unsigned i = 0; i < Rows * Columns; ++i) {
if(*data++ == x) {
// found
} }

View 1 Replies View Related

C :: Array Finding Position Of A Value?

Dec 24, 2013

So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:

Code: void Llogaritje1(int t[3][3],int &i, int &j){
int y,l;
for(y=0;y<3;y++){
for(l=0;l<3;l++){
if(t[y][l]==9){
i=y;
j=l;
break;
}
}if(t[y][l]==9) break;
}
}

But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.

View 4 Replies View Related

C :: Finding The Minimum Value Of Array

Sep 9, 2013

I am trying to make my program read a bunch of numbers in an array to find its maximum and minimum. the program will ask the user to enter in as much number as possible until they enter a non number/letter. i got my program to find the maximum value but the program couldn't read the minimum value. it always says zero. also everytime i enter the number 0, the program will just finish its loop statement. If i typed in a negative number, it'll read the negative number as its minimum.

Code:
#include <stdio.h>
int main()
{
//-------variables------------------
double list[1000]; // can hold 1000 items
int i;
char letter;
int max = list[0];
int min = list[0];

[Code] ....

View 5 Replies View Related

C :: Finding Diagonals Of Array?

Apr 11, 2014

Most of this program is working correctly, however when I get to the part on lines 70 to 78 to try and use the function on lines 103 to 113 to find out each diagonals value and then print each one back. But when this runs it only returns the value for [0][0] for each run through the loop and I'm not really sure why. I know its probably something simple but I'm just missing it,

Code:
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<time.h>
4 #define MAX 100
5
6 void display_menu();
7 int check_option(int);

[Code]...

View 4 Replies View Related

C :: Finding Mode Of Array

Mar 20, 2014

I've been trying for over an hour to think of the logic to find the mode of an array.I left out code for initializing the arrays, but all the values in the array are between 0-9. Check out my code below.

Code:

int mode( int array[], int size ) {
int i;
int count;
int max = 0;
int num = 0;
int mode;

[code]....

View 7 Replies View Related

C++ :: Finding The Average Of Array

Apr 16, 2013

I am attempting to write a program that takes a number(picked by the user) of test scores in an array then calculates the average and outputs the number of passed and failed tests.

On a side note I am attempting to use array notation in the main function and pointer notation in the other functions

#include<iostream>
#include<iomanip>
using namespace std;
int numScores;
int counter = 0;
double *scores;
//Function Prototypes

[Code]...

View 3 Replies View Related

C++ :: Finding A String Within Array?

Jan 14, 2013

i just want to check to see if one word (string) or one sentance is equal to any others within an array. My code

so basically i want to check if a is equal to either "sleep", "in", or "bed". Or even if the string within a is equal to "sleep in bed" as one string.

I have used the following but even if i get it correct and it says correct it says incorrect another 2 times because it is saying yeah you have gotten one right out of the possible 3. Even if I type "sleep in bed" it still does it (prints out incorrect another 2 times. Also are there any good books to start off with c++?

string a;
string aa[3] = {"sleep", "in", "bed"};
for(int i = 0; i < 3; i++) {
if(a == aa[i]) {
cout << "CORRECT!" << endl;
} else {
cout << "INCORRECT!" << endl;
}
}

View 18 Replies View Related

C/C++ :: Finding Element Of Array

Feb 17, 2014

"Write a program in C that finds the element of an array which all the previous are smaller and all the next are bigger than that.If there are more than one print the biggest. If there isn't any print "ERROR" .

EXAMPLE

If the array has 10 elements like this : {2,3,4,6,5,7,8,10,9,8}

The correct answer is 7 , because 2,3,4,6,5 are smaller than 7 and 8,10,9,8 are bigger than 7.

I am working on it for 2 weeks and I can't find a working solution />/>/>

There is the first try :

#include <stdio.h>
#include <stdbool.h>
int s_data[10]={2,3,4,6,5,7,8,10,9,8};
int main() {
int result,i,j,s_len ,tmp1,tmp;
bool GT_PREV,ST_NEXT;

[Code] .....

View 11 Replies View Related

C++ :: Count The Repeated Numbers?

Jul 12, 2013

I am using this code that to check a set of values from a text file and show it on the output.

Code: void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;

[code]....

I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-

Code:

The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

[code]....

So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -

Code:

The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6

[code]....

How can I do that?

View 3 Replies View Related

C++ :: How To Find Repeated Words

Aug 3, 2014

I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.

View 7 Replies View Related

C/C++ :: Repeated Numbers In A Matrix?

Apr 18, 2014

Given the matrix MxN, check if there are repeated numbers.

View 8 Replies View Related

C++ :: Counting The Repeated Number?

Jul 12, 2013

This function check a set of values from a text file and show it on the output.

void MatchNumber(int b){
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");

[Code]......

I want to calculate how many times the number is repeated. So I have used freq[num] in that function. But I am getting the output like this-

The common number is = 5
The 5 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

The common number is = 9
The 9 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

So the value of freq[num] only shows 1 instead of calculating the number of repetition.

View 3 Replies View Related

C/C++ :: Using Strings To Find Out If A Name Is Repeated?

Feb 10, 2014

I have to write a code that will read in n amount of names and the names. Then it will tell me if the first name entered has been repeated or not.

This is my input:

5 Bush Reagan Lincoln Bush Obama

This is my output:

First name in list is not repeated.
First name in list is not repeated.
First name in list is repeated.
First name in list is not repeated.

I would like to just give one answer; if it is repeated then the output should simply be "First name in list is repeated."

If the answer is that it was not repeated, I would like the output to say once "First name in list is not repeated."

// lastnames.c

#include <stdlib.h>
#include <stdio.h>
int main(void) {
char FIRST[25];

[code]....

View 2 Replies View Related

C++ :: Finding Highest Number In Array

Aug 12, 2014

after staring at this for awhile, I can't figure out why it won't work. It prints out numbers from 0 to 100, but will print out an absurdly high number as the highest number, like 790 or 640. I can't see why.

Code:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int find_highest(int array[]);
int find_highest (int array[], int size) {
int highest_num;
for (int i = 1; i < size; ++i) {
if (array[i] > array[i-1]) {

[code]....

View 1 Replies View Related







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