C/C++ :: Right Triangle Program - Computing Lengths Of Sides

May 5, 2014

I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514.

#include <stdio.h>
#include <math.h>
main() {
float angle;
float hypotenuse;
float adjacent;
float opposite;

[Code] ....

View 2 Replies


ADVERTISEMENT

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

C/C++ :: Program To Print Histogram Of Lengths Of Words In Its Input

Mar 4, 2014

Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation is more challenging.

See [URL] ....

I'm trying to do this exercise from K&R on my own (with my own code), but I'm receiving a signal (Illegal instruction (Core dumped)) when the input is too large.

#include <stdio.h>
#define MAXWORDLENGTH 10
int main(void) {
int c; /* Character read */
long length[MAXWORDLENGTH + 1];
int reading_word = 0;
int word_size = 0;

[Code] ....

Where the problem might be occurring. I tried debugging with GDB but found no useful information.

Program received signal SIGILL, Illegal instruction.
0x00007ffff7a3b76e in __libc_start_main (main=0x4005d4 <main>, argc=1,
ubp_av=0x7fffffffe2a9, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffe298) at libc-start.c:258
258libc-start.c: No such file or directory.

The program output is also wrong when tested with the code provided at the link given above.

View 7 Replies View Related

C++ :: Dice (with Varying Number Of Sides) Program To Calculate Percentage Of Results

Oct 28, 2013

I am trying to code and compile a program that requests a uses to first inpu the number of sides they wish for a dice to have and secondly input the number of dice throws they would like to calculate the value for. The program will print an error message and default the number of sides the dice has to 5 if the number entered is below 4. Finally it will print out a percentage figure for each value that results from all the the dice rolls.

I have attached my header, driver and class files below along with accompanying error messages below them

// file name Exercise.cpp
#include <iostream>
#include "Die.h"
using namespace std;
int main() // the main program begins here
{
char restart = 'y'; // declare variables
double numRolls = 0.0;
int diceTot = 0;

[Code] .....

View 5 Replies View Related

C :: Program Is Not Computing Averages From Array

Sep 23, 2013

This code is not computing the averages.. I am trying to add up all the values in the array and divide them by the number of addresses in the array

Here is the snippet of what I have do far :

//Run through all possible train combinations

Code] :

for(tl=10; tl<=max_tl; tl+=8) {
n_cars++;
num_trains=(.25*max_track)/tl;
num_people=n_cars*num_trains*4;

[Code] ....

View 10 Replies View Related

C++ :: Right Triangle Program Using X And Y

Jan 12, 2015

I originally had the user input three different lengths and then used this to determine whether or not it was a right triangle.

if(c==sqrt(a*a+b*b)||a==sqrt(b*b+c*c)||b=sqrt(a*a+b*b))

Now it has to be modified in order to accept the input 2,2 4,4 and 6,8(only an example) and be able to find out if it is a right triangle. I was told that arrays were not necessarily the only way to go about it.

View 1 Replies View Related

C/C++ :: 3x3 Magic Square That Sums Up To 15 On All Sides

Mar 10, 2015

I have an assignment that I have to make a 3x3 magic square that sums up to 15 on all sides. I can't use arrays, just Loops and If and Else statements.

My first attempt was like this

//Program for printing magic square that sums up to 15.

#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e, f, g, h, i;
int r1, r2, r3;
int c1, c2, c3;

[Code] .....

I can't think of a way to loop that when it prints out, it will have a sum of 15 on all sides and/or print one of the 8 solution for a 3x3 magic square.

View 3 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

I'm making a program that prints a triangle of @ signs given rows (but not columns).

For example, the output with rows = 4 would be:
@@@@
@@@
@@
@

and rows = 3 would be:
@@@
@@
@

However, trying to make this has given me a program that does something similar (but not the same):

for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@

and rows = 3 gives
@@@
@@
@

It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:

1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.

My current code is:

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;

[Code] ....

I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?

View 4 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C++ :: Program To Calculates Hypotenuse Of A Right Triangle

May 12, 2014

How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far

#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;

[Code] ....

View 4 Replies View Related

C++ :: Program To Find Area Of Triangle?

May 26, 2013

i have written a program to find area of triangle, but i meet some errors,

//******area of triangle******//
#include<iostream>
using namespace std;

[Code].....

View 1 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols In A Certain Direction

Jan 12, 2015

So I need to make a program that prints a triangle of symbols in a certain direction.

For example: Code: How many rows? 3

@
@@@
@@@@@

How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {

[Code] .....

View 6 Replies View Related

C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.

Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));

[Code] ....

View 7 Replies View Related

C++ :: Program That Will Represent Axis-aligned Right Triangle In X-y Plane As A Class

Apr 10, 2013

I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:

#include <iostream>
#include <cmath>
using namespace std;
class Point {
private:
double px;
double py;

[Code] .....

How to get void Triangle::setBottomLeftX(const double x) to work.

Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.

a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.

View 19 Replies View Related

C++ :: Tree Arrays Of Same Even Lengths And Adds Values At Odd Indexes

Oct 22, 2013

I am trying a program with that takes tree arrays of same even lengths and adds the values at odd indexes and save at even index of 3rd array and voice versa........

what will be the logic i have tried it a lot of time not worked................

View 3 Replies View Related

C++ :: PolarSSL SHA512 Wrapper - Differing Hash Lengths

Apr 10, 2013

I'm trying to write a little C++ wrapper around the PolarSLL SHA-512 / 384 implementation, the source code of which you can view here: [URL] .....

The problem I'm having is that the length of the digest is not always 64 bytes (for sha512) or 49 bytes (for sha384) as it's supposed to be, it often is, but not always.

I have pretty much used the code as it is on PolarSSL's website, except for wrapping it in an "impl" namespace. I also ran the self_tests, which all passed.

Here's the code I'm using to wrap the PolarSSL implementation:

namespace {
void sha4(const std::string& input, const sha_t& type, std::string& result) {
bool is_384 = (type == sha_t::SHA_384);
const unsigned char* in = reinterpret_cast<const unsigned char*>(input.c_str());

[Code] ....

When I do a strchr() for '' on the original (non-hex) values, the pointer position returned is the same as the checksums length, so I'm wondering if perhaps the sha4 implementation would shift bits around and one of them happens to become a '', null terminating the hash early?

View 3 Replies View Related

C++ :: Computing Net Pay - Too Few Arguments

Apr 13, 2013

double compute_taxes(double gpay) {
double gross;
double td; // to hold the tax deduction
if (gross <= 1000)
td = gross * 0.5;
else if(gross < 1500)
td= gross * 0.6;

[Code] ....

Write the function double compute_npay(double gpay) that receives an employee's gross pay using the value parameter gpay, computes the net pay and returns it. the net pay is the gross pay - the tax deduction. To compute the net pay, it first calls compute_taxes() to compute the tax deduction.

View 4 Replies View Related

C :: Computing Ratio With Array?

Feb 10, 2014

What is wrong with this code cause im not getting the correct ratio of total people to cumulative length?

Code:
#include<stdio.h>
#include<stdlib.h>
//define constant variables
#define FIRST_CAR_LENGTH 10
#define NORMAL_CAR_LENGTH 8
#define CAR_CAPACITY 4
int main(void){
//Set up some variable with values that come from input or calculations

[Code].....

View 7 Replies View Related

C/C++ :: Computing Bit Difference Between Two Arrays?

Jul 23, 2014

#include <stdio.h>
#include <stdlib.h>
int b_diff (int, int);

[Code].....

I am trying to take two arrays H[], and V[] and call each element to compute the bit difference(Hamming distance) and return that back to the main function to be used in calculating pixel_phase and pixel_smoothing. I'm getting an error that bit_diff cannot be used as a function and I've tried renaming it but nothing seems to work.

[ int b_diff (int a, int ] is how it should actually look.int b_diff (int a, int is how it should actually look).

View 14 Replies View Related

C++ :: Computing The Riemann Zeta Function?

Sep 30, 2013

I'm suppose to provide an inner loop that computes the zeta function and the other loop is just press y for to continue, anything else exit.so far i got this:

#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main() {
double x, n,zeta;

[code]....

I can't seem to get the formula right.

View 2 Replies View Related

C++ :: Recursive Function For Computing Total Route

May 11, 2014

How to do recursive function for the following?

RecursiveComputeRouteDistance(p1index,p2index,locations,latitudes,longitudes): recursively computes the total distance between all waypoints (route) using computeDistance function to compute the distance between two adjacent points. You need to recursively compute the distance for the base case(s) and the general case(s).

This is my computeDistance function

int computeDistance(double a1,double b1,double a2,double b2) {
const int R=6378136;
const float Pi =3.14159;
float Dist=0;
Dist= ((Pi*R)/180)* acos((cos(a1)* cos(b1)* cos(a2)* cos(b2)) + (cos(a1) *sin(b1)* cos(a2)*sin(b2)) + (sin(a1)*sin(a2)));
return Dist;
}

View 2 Replies View Related

C++ :: Finding Pi Through Computing Area Of A Quarter Circle?

May 4, 2015

question: Finding pi through computing area of a quarter circle

my code

PHP Code:

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    int sum=0;            
    double PI,h,x;            
 
[Code] .....

View 14 Replies View Related

C :: Verified Code For Computing Fast Furrier Transform Of Image

Jun 9, 2013

i am looking for a verified code in simple c, for generating fft of an input image (.jpg). the output can be a text file including fft coefficients.can you recommend me any source except open-cv?

View 6 Replies View Related

C :: Computing Grades From Input File And Writing To Output File

Aug 31, 2014

One of my class assignments is to create a program that receive a .txt file containing a students name and their grades as follows: John K. 99, 87, 57, 89, 90, 95 Amanda B. Jones 100, 88, 76, 99, 86, 92 etc.. The number of students is unknown until run time. You have to take those grades and average them weighing the first (4) at 10% a piece and the next (2) at 15% each and the final at 30%. Then return an output file with the students name and their letter grade A,B,C,D,F based on their computed score. In addition, on screen it needs to display the average scores for each Q1, Q2, etc. as well as the minimum and maximum for each test on the screen. I am having a hard time in assigning the scores to a variable so that they can then be computed as an average and then used to determine a letter grade. I have begun to write the code and am a bit stuck..here's what I have so far:

Code:
//
// main.c
// Final Exam
//

[Code].....

The problem I'm having now is how to go about passing the grades to the function computeGrade and then compute the average and return that to the function.

View 4 Replies View Related

C++ :: Printing A Triangle

Oct 7, 2013

What the heck is wrong with my logic? I just print a rectangle!!! I have played with thing for ever it seems. I thought the rotating part would be hard but now I find myself stuck.

Code:
#include <istream>
#include "triangle.h"
using namespace std;
void triangle::create_triangle() {

[Code] ....

View 13 Replies View Related

C :: Finding Out Neighbors Of Triangle

Mar 2, 2015

I need to find out neighbors of a triangle and loop it over entire unstructured grid. How to do it?. Cell numbers are random so I am unable to loop over all cells.

View 9 Replies View Related







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