My code compiles fine but it doesn't seem to want to calculate the max integer. It calculates min and average fine but I'm not seeing what is wrong with my code. The max integer keeps coming out wrong.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cstdlib>
#include <algorithm>
using std::swap;
And here is my output when I run the program. 75 Max: 90 Min: 0
Press any key to continue . . I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min.
I want to find third largest character in ascii as alphanumeritic. The problem is i cannot use arrays. How can I find third largest number ? Have to I compare all chars with each other ?
I need to calculate the expected time it takes to do an activity using a formula provided and after the loop is broken it needs to show the number of projects processed and the project with the longest expected time. I've got everything working except for finding the the project with the longest expected time. What I have here just keeps displaying the number of the last project processed regardless of if it was the largest or not, specifically lines 54-61 is what i can't seem to figure out.
#include <stdio.h> int main( void ) { unsigned int counter; int projectnumber; int optimistictime; int realistictime;
I'm trying to write a program that will allow a user to enter infinite numbers (one at a time) with a way to stop entering values, and once it stops it immediately displays:
Lowest number: Highest number: Number of values entered: Average of numbers:
what I can't figure out is:
-how to end the loop with something other than a number, preferably a char, so that it doesn't affect the average/lowest/highest
-how to output the lowest and highest numbers in a loop (would be easier to figure out were it finite and I could just type a bunch of printf/scanf)
What I have so far:
Code:
#include <stdio.h>#include <stdlib.h> #define pause system("pause") main(){ //n = amount of numbers input //x = number given by user //s = smallest number //l = largest number }
I am trying to find the largest prime factor of a number. But when I am trying to determine if a number is a prime number in the function:
int is_prime(int number), I am unable to exit the loop.
Here is the code:
#include<iostream> using namespace std; int is_prime(int number) //the problem is in this function { int num = number; int factor=0; do{ num++; for(int i=1;i<(num+1);i++){
[code].....
So when the program runs, it first divides 20 by 2, to get 10, then divides 10 by 2 to get 5. Since, // condition 1 is not met, it passes 2 to the function int is_prime(int number). The function is able to return 3, but cannot exit the loop when num is 4.
I think the problem lies in the function: int is_prime(int number).
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.
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.
In this assignment, you are required to write a function called largest square. Your function should take a 2 dimensional array, 2 integers which represent the number of rows and columns in the array, and prints out a 2 X 2 array which represents the largest square in the array. The largest square means the square for which the sum of its elements is the greatest in the array. Submit your function in a file called largestSquare.c
Example: Given the array 1 2 3 4
5 6 7 8
9 10 11 12 the output should be 7 8
11 12
Example 2: Given the array 8 2 6
3 7 3
6 1 1 the output should be 8 2
3 7
The prototype of your function is void largestSquare(int[rows][columns], int rows, int columns).
Am I anywhere close with what I've started?
// // main.c // largestsquare //
#include <stdio.h> #include <stdlib.h> int main(int argc, const char * argv[]) { int rows, columns;
I'm trying to create a function that determines the largest value in the array and then outputs the value and index. I want to values in the array to be random so I tried using the rand function, although I'm not sure where I'm supposed to put it. My main problem (I think) is outputting the correct values...
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void lastLargestIndex (int numbers[], int arraySize); int main(int argc, char** argv) { int number, arraySize = 50;
I am required to write a program which, when given an nxn 2D array of char, and the specified coordinates of a specific point in that array, returns thelargest number of horizontal, vertical or diagonal contiguous (side-by-side) sequence of points of that same char value that intersects with the given point.
The way I took on this problem was to:
1) First find out the number of points with the same char value up, down, right, left, north-east, north-west, south-east, and south-west of the given point.
2)Add up+down+1(the one is for the point itself), north-west+south-east+1, etc...
3) Finally I compared the four values (updown, rightleft, NESW, NWSE) and returned the largest one.
Well, that's how the program is supposed to work in theory but as you can probably guess it doesn't work. In addition to telling me what I'm doing wrong, is there a simpler way to do what I am trying to accomplish?
Here's the code:
Code:
int findLongest(char **board, int n, int row, int col) { char current; int rightleft, updown, NESW, NWSE; int r, c, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, d; int t1=1, t2=1, t3=1, t4=1, t5=1, t6=1, t7=1, t8=1; current=board[row][col]; //check Above: col remains the same for(r=row-1;r>=0||t1!=0;r--) //with the condition r>=0 I made sure not to accidentally check values outside of the array
I wrote a program with a recursive() called finder. But it dose not work properly,at run time it becomes to a infinite status. How to detect the error at runtime. Here is the code.
#include<stdio.h> void finder(int x,int y); int tot;
[Code] ....
I think the error is the changing value of x after a round of for loop.
I have written a delete node function to delete a node in a linked list by the index number. Here is the code:
Code:
void delete_node(struct node **start,int index_no) { int counter=0; struct node *current=*start, *prev=NULL;//Current holds start and prev holds previous node of current while(current->next!=NULL)
[Code]....
note that I know if the head node turns out to be the indexed position, there is no way to delete that node in the current coding. But please after correcting the present node add that part of the code separately.
How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?
I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer. And I cannot use strings or arrays.
why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/
#include <stdio.h> #include <iostream> #include <time.h> using namespace std; int TEST (int arrayA[], int arrayB[], int j); int main() { srand (time(NULL));