C30N9's Doomworld Forums Blog

C30N9's Doomworld Forums Blog

Can anyone explain this to me? April 13, 2015, 12:25 pm
EDIT: Nevermind, I misunderstood it at first. I thought that when I add "6", it would add to array[5] (or the sixth element of the array). Problem solved.

This is for an assignment. I'm not asking for the solution, but I'm a bit confused:


Write a C program to create and manipulate a one dimensional array (list) of up to a hundred sorted (ascending order) numbers by using functions to insert, remove, or print elements as follows:
- Function insert: will search for the appropriate position of a given element and if the element is already in the list will display an error message. If not, the function will shift all the elements starting from the position of the element to the right of the array and then insert the element into that position.
- Function remove: will search for the element to be removed and if not found will display an error message. If the element exists, the function will remove it and shift all the elements that follow it to the left of the array.
- Function print: will print the elements that exist in the array at that point.
Your program should display a menu to the user that allows him/her to insert, remove, or print as many elements as they want until they want to stop. If an element is inserted into an already full list, an error message should be displayed. The array (list) at the beginning should be empty.

Example of a sample run:
Enter your choice: 1) insert 2) remove 3) print 4) exit
2
List is empty, No change
Enter your choice: 1) insert 2) remove 3) print 4) exit
1
Enter element to insert
6
Element 6 is inserted
Enter your choice: 1) insert 2) remove 3) print 4) exit
1
Enter element to insert
9
Element 9 is inserted
Enter your choice: 1) insert 2) remove 3) print 4) exit
1
Enter element to insert
7
Element 7 is inserted
Enter your choice: 1) insert 2) remove 3) print 4) exit
2
Enter element to remove
112
Element 112 does not exist, No change
Enter your choice: 1) insert 2) remove 3) print 4) exit
2
Enter element to remove
6
Element 6 is removed
Enter your choice: 1) insert 2) remove 3) print 4) exit
3
Elements in list are:
7
9
Enter your choice: 1) insert 2) remove 3) print 4) exit
1
Enter element to insert
7
Element 7 already exists, No change
Enter your choice: 1) insert 2) remove 3) print 4) exit
4
Goodbye




It seems to me that the example is wrong, shouldn't element 7 become 6? And what if the 100th element (99) is shifted to the right? They didn't say anything about the limits.
0 Comments

Solving equations with e ^ x and x April 1, 2015, 7:10 am
Today, in my Calc II exam, I've came across the question of finding the derivative of an inverse function when x = 2. The function was as I remember:

f(x) = e ^ 2x + 4x + 1

I didn't know how to solve for x algebraically after I substituted f(x) with 2 (or using ln or exp functions). So I put automatically x = 0 as it will satisfy the equation and then I proceeded. Luckily, it was a multiple choice question, so the method of solving isn't important.

How do I solve this?
7 Comments

[SOLVED] Why is the output negative? March 10, 2015, 9:59 am
This code is supposed to calculate e to the power x. It works fine at lower numbers, but then at x = 3.6, the output starts to decrease as x goes up. What's wrong?

C language.

EDIT: The problem was that "factorial" function was an int, so at high values, it won't work.


#include <stdio.h>

double factorial (int n) {

double f_result = 1; //factorial result
int i;

for (i = 1; i <= n; i++)
f_result *= i;

return f_result;

}

double power (double base, int exponent) {

double p_result = 1; //power result
int i;

for (i = 1; i <= exponent; i++)
p_result *= base;

return p_result;
}

double compute_ex (double x) {

double division = 1;
double div_sum = 0;
int counter = 0;

while (division >= 0.0001) {

division = power (x, counter) / factorial (counter);
div_sum += division;

counter++;

}

return div_sum; //div_sum is the sum of the infinite series, which is e to the power x

}



int main()
{

double x;

printf ("Enter the value of x:\n");
scanf ("%lf", &x);

printf ("e to the power %.1lf = %.2lf", x, compute_ex (x));

return 0;

}
9 Comments

Minor in mathematics February 25, 2015, 1:27 pm
I'm majoring in computer science (first year), and I'm thinking of taking minor in math. The reason is because of its connection to computer science (since it's a sub-field of math), and I like it a lot. The question is, are these a good pair?

For CS degrees, math courses include Calculus I and II, Discrete Mathematics, Statistics, Linear Algebra and Numerical Methods. As for the mathematics minor, it includes Calculus III, Foundations of Mathematics, Normal Differential Equations, Mathematical Analysis I, Abstract Algebra I and other math courses in the choice of the student.

I feel getting a minor in math is a waste of time. It's because where I live, computer scientists and engineers usually end up in programming jobs, or maintaining computers. So it's very likely that I won't work in the "theoretical" part of computer science, and I "assume" that math is applied more on the theoretical part than programming (or software engineering).

Shall I forget it and pursue other minors, or am I being ignorant about how good it is to study such pair?
2 Comments

Shall I switch majors? December 19, 2014, 9:30 am
I'm currently majoring in Computer Science, but it is possible to switch to Computer Systems Engineering. In general, CS should focus more on math, theories and software-related stuff than CSE, but after looking through my university's guide for BA degree, it seems that CS is a bit "contained" in CSE. For example, CSE students take several courses that are essential to get into software engineering (programming, data structure and management, and software engineering courses), with another courses related to Electrical Engineering and hardware stuff, but some share the same name of other CS courses (AI, Operating Systems, Algorithms). Plus CSE students can take some courses in CS as elective courses.

You have to be good in Physics and Mathematics to switch or to do well, which I am good at both. I just keep feeling that I'm wasting a chance to study engineering and become good at both software and hardware rather than only focusing on Computer Science. At the end of the day, either degrees will likely get me the same job, but an engineer is usually generally known as being smarter (because he is an "engineer", plus the requirements to get engineering are harder than the ones to get into CS).

Should I stop listening to people who keep telling me that I've took the wrong choice choosing CS over CSE even though I can make it through in the latter major?
0 Comments

Aligning text in html November 25, 2014, 9:40 am
I have a form in html, but I don't know to make it perfectly aligned. I tried putting it in a table with two columns, but I still have problems:

3 Comments

HTML error November 7, 2014, 5:54 am
Styles aren't applied to the text. Why?

<html>

<head>
<title>Personal Info</title>
</head>

<body>
<p>
<h1>
Name:<br>
ID:<br>
Average:<br>
Age:<br>
</h1>
</p>
<hr>
<p style = “color:green; text-align:center"><h2>Social status:<br>
Phone Number:<br>
Address:<br>
</h2>
</p>
<hr>
<p style = “color:red; text-align:right”><h3>Date:<br>
Signature:
</h3>
</p>
</body>

</html>
2 Comments

got some physics y'all October 6, 2014, 4:07 pm
1- A car, initially going eastward, rounds a 90 degrees curve and ends up heading southward. If the speedometer reading remains constant, what's the direction of the car's average acceleration vector?

2- A plane with airspeed 370 km/h flies perpendicularly across the jet stream, its nose pointed into the jet stream at 32 degree from the perpendicular direction of its flight. Find the speed of the jet stream.

3- An object undergoes acceleration 2.3i + 3.6j m/s^2 for 10 s. At the end of this time, its velocity is 33i + 15j m/s. What was its velocity at the beginning of the 10 s interval? By how much did its speed change? By how much did its direction change? Show that the speed change is not given by the magnitude of the acceleration multiplied by the time. Why not?

4- A particle leaves the origin with initial velocity v0 = 11i + 14j m/s, undergoing constant acceleration a = -1.2i + 0.26j m/s^2. When does the particle cross the y-axis? What's its y-coordinate at the time? How fast is it moving, and in what direction?

5- A jet is diving vertically downward at 1200 km/h. If the pilot can withstand a maximum acceleration of 5g before losing consciousness, at what height must the plane start a quarter turn to pull out of the dive? Assume the speed remains constant.
8 Comments

University - Day 1 September 8, 2014, 8:22 am
So much "free" time (1-2 hours) that I hate to sit lonely in public, so I went/hid in the library which is a very friendly environment for spending time yourself. This is gonna be boring if I'm going to do this everyday.
2 Comments

If y(t) = 100e ^ 0.1t then the doubling time is... August 23, 2014, 1:55 pm
?

Also how is doubling time calculated in general.
10 Comments

Next