C++ :: Find Smallest In Array Of 7 Numbers

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


ADVERTISEMENT

C/C++ :: Find Smallest Number In Array Filled With Random Numbers

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

C++ :: Write A Source Code That Find Smallest / Largest And Average Of Numbers From Array

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

C++ :: How To Find The Smallest Number Amongst 4 Numbers

Nov 28, 2013

How to find the smallest number amongst 4 numbers

View 10 Replies View Related

C/C++ :: Find Second Smallest Number Out Of 4 Numbers

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

C :: Find Smallest / Largest And Average Values In A Collection Of N Numbers

May 30, 2014

I seem to have reached a dead end in a program I am attempting to write.The purpose of the program is find the smallest, largest, and average values in a collection of N numbers. It needs to get the value of N before scanning each value in the collection of N numbers.I'm having trouble creating comparisons for each set. I have a feeling because of the way I structured my program, I'm unable to make a proper comparison. Maybe my approach was wrong as soon as I got to the for statement to loop N sets and N numbers.Here is my code so far:

Code:

#include <stdio.h>
int main (void)
{
int num_sets, num_of_integers;
int count, count2, set, sum = 0;
int num, avg;
}

[code]....

/* Here is where I would continue to attempt to make a comparison between sets to determine smallest to largest */

return 0;

View 5 Replies View Related

C++ :: Find Smallest Number In 2D Array

Oct 21, 2014

I need to generate a grid of 10x8 and fill it with random numbers (max 70), then i need to find the smallest number within the random numbers generated and my "findSmallest" function does not seem to work and i do not know how to make it work...

Here my Code:

include <iostream>
using namespace std;
int main() {
int row=0;
int col=0;
int ArrayGrid [9][11];
srand(time(NULL));

[Code] .....

View 4 Replies View Related

C/C++ :: Sorting Numbers In Array From Largest To Smallest?

Mar 16, 2014

I'm trying to sort the numbers in an array from largest to smallest and print it but whenever I run this it does not sort anything at all.

#include <stdio.h>
#define SIZE 10
void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);
size_t counter1 = 0;
int average;
int main( void ) {
int array1[ SIZE ];

[code]....

View 4 Replies View Related

C/C++ :: How To Find Smallest And Largest Number

Oct 18, 2014

Write a program that will find the smallest, largest and average of the values in a collection of N positive integer numbers.

View 12 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

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

C :: Find Duplicate Numbers And Numbers Found Once In Array

Dec 7, 2013

Question: How to find a duplicate numbers and numbers found once in array.

View 7 Replies View Related

C++ :: Program To Find Smallest Real Factor Of A Number

Oct 10, 2013

I need codes for a program in C or C++ that will show the real factor (the smallest one, without the number 1) when an integer is given as input.

When the program is started, it will ask to enter a number and press enter. After entering a number, it will first check if it is a prime number or not. If prime, it will notice that it is a prime number, otherwise, it will print the smallest real factor of the given integer.

For example, if 12 is entered, it will print, the smallest real factor for this number is: 2

If 27 is entered, it will print, the smallest real factor for this number is: 3

...and so on

View 12 Replies View Related

C :: Find The Largest And Smallest Number Entered By User?

Mar 6, 2015

How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.

I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){

int maxNum=0, minNum=0, value, count=0, sum=0;
double average;

[Code] ....

View 4 Replies View Related

C++ :: User Defined Functions - Find Largest And Smallest Number

Nov 16, 2013

I am writing this code, and I every time I run question A, no matter what numbers I put in, I get "larger = 0.

#include <iostream>
using namespace std;
int awesome ();
int best ();
int crazy ();
int main () {
char letter;
int smallestNumber;
int largestNumber;

[Code] .....

View 2 Replies View Related

C/C++ :: Cannot Get Largest And Smallest Numbers Using Functions

Feb 6, 2015

#include<iostream>
using namespace std;
int computeTotal();
int findSmallest();
int findLargest();

[Code] .....

View 4 Replies View Related

C# :: Getting Largest And Smallest Values From Random Numbers?

Dec 2, 2014

The only part I have working is getting all odd random numbers but the logic in getting the largest and smallest from random is what is giving me alot of trouble.

class Program {
static void Main(string[] args){
int num = 0;
int largest = 0;
Random rand = new Random();
for (int ctr = 1; ctr <= 100; ctr++)

[code]....

Console.Write("{0,5} The larget number out of 100 odd numbers is: {1:n}",y,largest);

View 4 Replies View Related

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 View Related

C :: Find Prime Numbers - How To Use Bit Array

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

C++ :: Input Three Integers From Keyboard - Print Smallest And Largest Numbers

Nov 18, 2013

I am trying to Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. How do i go about it. What i dont know is how to come up with smallest and largest number .

View 1 Replies View Related

C++ :: For Loop - Display Smallest And Largest Numbers From User Input

Jul 29, 2013

I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.

This is what I have ....

#include <iostream>
using namespace std;
int main() {
int amount;
int count;
int number = 0;
int smallest = 0;
int largest = 0;
cout << "Enter total numbers to process: ";

[Code] ....

View 4 Replies View Related

C/C++ :: Find Average Of 10 Numbers Passed To Array Using Function?

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

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++ :: Finding Smallest Number In Array?

Oct 17, 2014

I was assigned to create a program that has a 10 x 8 two dimensional array and fill it with random numbers in the range 50 to 70 inclusively.( Got That part down). The second part is to make function named findSmallest that will find and print, appropriately labeled, the smallest number in the array.

I cant seem to get it working. The code for finding the smallest give me some weird number

Here my Code:

//Assignment 18 Program 2
#include <iostream>
using namespace std;

[Code].....

View 2 Replies View Related

C/C++ :: Ordering Array From Largest To Smallest?

May 25, 2014

Write a program that reads in a list of integers into an array with base type of int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest.

For example, for the input
-12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

the output should be
N Count
4 2
3 3
2 2
1 4
-1 1
-12 4

Here's My code So far:

#include <iostream>
#include <fstream>
using namespace std;
const int SIZE = 50;

[Code]....

My Code outputs the numbers From Largest to Smallest according to given array, but I need to make it to output the numbers once(if its repeated)

View 2 Replies View Related

C :: How To Calculate Largest / Smallest / Average - No Array

Feb 16, 2015

i'm having trouble trying to make this code works .. the program must repeatedly asks user for the age of a person until user enters -1 ,, once he/she entered -1 the program calculates ( smallest value entered, largest value , and average )excluding -1 from calculation

i've been working on this for a weeks this is the best i could do.i know average must add all the entered values , not only smallest and largest but how can i do that here ?

Code:

#include<stdio.h>
int main(void)
{
int age ;
int v;
int counter;
int l=0;
int s=0;
int limit;
}

[code]....

View 13 Replies View Related

C++ :: Finding Second Smallest Element In Unsorted Array

May 5, 2013

How should I go about finding the 2nd, or 3rd smallest element in an array? Where the minimum is not equals to the next minimum.

Here is the psuedocode I've found

void Min(A[i..j], int&min, int &next_min)
if (i=j) then min=A[i] and next_min = infinity
else
mid = (i+j)/2
Min(A[i to mid]),a,b)
Min(A[mid+1 to j],c,d)

Let min be minimum among a,b,c,d

Let next_min be the next_min among a,b,c,d

min != next_min

Here is what I wrote but it does not seem to work.

#include<iostream>
#include<vector>
#include <cstdlib>
using namespace std;
void minfind(vector<int> &array,int left,int right, int &min, int &next_min);

[Code]...

View 5 Replies View Related







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