C/C++ :: Program To Display First 10 Largest Numbers Present In A File?
Oct 15, 2012
there is a file contains only a numbers ,we dont know how many numbers present in that file.so i want a program to display top n largest number present in that fie.(n may be 5,10,12 like that.)
View 3 Replies
ADVERTISEMENT
Oct 9, 2013
My display is producing:
Enter the first number:234
Enter the second number:2
Enter the Third number:3
The largest number is 3
#include <iostream>
using namespace std;
double larger(double n1, double n2, double n3);
int main() {
[Code] ....
View 1 Replies
View Related
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
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
Feb 12, 2013
I'm writing a program that stores records into a file and then these records can be printed out. A last name, first name, and score is stored to be exactly 36 characters long (using leading spaces to pad) making it easier to retrieve specific records. For example, three records stored in the file would like like this: (the underscores are simply to illustrate the distance, they are not in the file itself)
_______lastname_______firstname__90__________lname __________fname_100___________last___________first __60
When printed out, the names are formatted as follows:
lastname, firstname: 90
lname, fname: 100
last, first: 60
However, when I print them out this is what I get:
lastname, firstname: 90
lname, fname: 100$
last, first: 60H
For some reason, for any record after the first, an extra character is added to the end. These characters are not in the file, so I was thinking that the array for some reason wasn't being filled completely, (the array is initialized to size 36 and 36 characters are read from the file using fread) so it was printing out a random character assigned to the 36th array position. Except the character never changes, (always a $ for record 2, H for record 3, l for record 4 if i remember) and I've tried reducing the array size or the number of character read and it's the string that gets altered, the random character always remains. I figure the problem must be in the print_records function (appending seems to work no problem). Anyway here is my print records and appending records code.
Code: /*
- Prints a single record stored in the file pointed to by ifp.
*/
void print_record(FILE *ifp, int record) {
[Code]......
View 6 Replies
View Related
Dec 4, 2013
I am working on a c++ assignment and I need to display the smallest and largest values of an array called from a .txt file...but I don't know how to display them...
This is what I have so far::
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
[Code].....
and the .txt file is:
12 43 11 10 9 54 36 75 96 83 23 35 67 35 47 58 69 13
45 67 89 78 66 44 1 55 59 81 18 0 42 199 4 100 46 76
View 2 Replies
View Related
Oct 4, 2014
This is a program that display prime numbers from 1 to 100. it has problem linking when i run the program.
#include <iostream>
class Prime {
public:
int PrimeNo();
int Display();
};
// class Prime number
int Prime::PrimeNo()
[Code] ....
View 3 Replies
View Related
Feb 25, 2014
Write a program that displays the first 40 Fibonacci numbers. A Fibonacci number is created by add the previous two, with the first two always being 0 and 1. A partial sequence is as follows:
0, 1, 1, 2, 3, 5, 8, 13, 21,….
Your table must display 6 numbers per row and use a spacing of 10 for each number. Don’t forget to include the header file “iomanip” at the top and use “setw()”. You will need to turn in an algorithm, source code and output.
Here is what i have but i get errors!
#include <iostream>
using namespace std; {
int FirstNumber = 0;
int SecondNumber = 1;
int NumberOfNumbers = 2;
int NewNumber;
[Code] .....
View 3 Replies
View Related
Apr 25, 2014
I am reading a file whick looks like following:
Code:
10 = NAND(1, 3)
11 = NAND(3, 6, 5)
15 = NAND(9, 6, 2, 8)
Problem: I have to find the word "NAND" and then find the numbers inside the brackets because they are the inputs to that NAND gate. I have written a code below but that code can detect the fixed number of inputs. I need a code which can detect any number of inputs (whether 2 inputs or more than two). But i don't understand how do i do that?
My code:
Code:
string input_str ("INPUT"), output_str ("OUTPUT"), nand_str("NAND");
while (getline( input_file, line ))
{
std::size_t guard_found = line.find(guard_str);
[Code].....
View 8 Replies
View Related
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
Apr 1, 2013
I have a file with numbers and want to display it on the screen.
View 15 Replies
View Related
Mar 25, 2013
I'm trying to find the two largest numbers out of ten. I've re-done this problem several times and it still doesn't work.
Code:
#include <stdio.h>
int main(void) {
float number;
float largest;
float secondLargest;
float counter;
float temp;
}
[code]....
View 9 Replies
View Related
Feb 6, 2015
#include<iostream>
using namespace std;
int computeTotal();
int findSmallest();
int findLargest();
[Code] .....
View 4 Replies
View Related
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
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
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
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
Sep 26, 2013
I'm trying to make an array that takes a group of numbers and finds the largest number into a template class.
template<class TYPE>
void Integers(TYPE data) {
int integers[] = {4, 25, 32, 85, 150, 12, 98, 200};
int i = 0;
int Max=integers[0];
for (i=1; i < 8; i++) {
[Code] ....
I'm sure I'm going about it all wrong, but I'm not sure as to get it so that it will accept the arrays input.
View 2 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
Jan 30, 2013
find inserted numbers, let say 10 numbers and find the largest and second largest number with their position in an array?
View 3 Replies
View Related
Jun 5, 2013
i want to create a program (in c++ or c#) that will play mp3 files but also display a word file with the lyrics of the mp3 song playing. so if i choose a mp3 file from a list, the lyric file for that song should also be displayed. i have all the mp3 and lyric files saved on the computer so my problem is how can i link the files?
View 5 Replies
View Related
Jan 6, 2015
I am new in c programming. I want to write a function that will count the empty line of the file and display the content.
/* ***************************
** creator: firstprint *
******************************/
#include <stdio.h>
/* function that will identify if line is empty or not */
is_empty(char *buffer) {
while(isspace(*buffer)) buffer++;
if(*buffer==0x00) return 1;
[Code] ....
View 4 Replies
View Related
Apr 28, 2014
Write a program that uses two functions; one finds the largest number and second largest number; and second function finds the average. The data, comprising of 20 different temperature values, is available on a file.
View 1 Replies
View Related
Jul 29, 2014
I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.
Code:
void CColorDisplayView::OnDraw(CDC* pDC) {
CColorDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;
[code].....
View 10 Replies
View Related
Feb 27, 2013
I made the code that stores and prints 5 row by 5 column values but how to find the largest number from them.What should I do to find the largest number?If I use if-else then it would be very tedious but I think there is way out with for loop but still I can't frame the logic. Here is the code
Code:
#include<stdio.h>
main() {
int lnum[5][5];
int i,j;
for(i=0;i<=4;i++) {
[Code] .....
View 7 Replies
View Related
Mar 13, 2014
I've a big problem. I'd like to generate of all permutations of objects present on my list and i don't know how to do this. I've found a few examples, but i can't use them in my code...
#include <iostream>
#include <string>
#include <list>
#include <fstream>
#include <cstddef>
#include <cstdlib>
#include <iterator>
using namespace std;
class Item {
private:
[Code]...
Input file with objects:
3
2 0 0 4
5 0 1 5
3 0 2 6
and output should be:
2 0 0 4
5 0 1 5
3 0 2 6
2 0 0 4
3 0 2 6
5 0 1 5
3 0 2 6
2 0 0 4
5 0 1 5
etc... 3! so 6 permutations for this example.
I was 'fighting' with this for few days, and I'm so downcast.
View 2 Replies
View Related