Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-06-2008, 10:04 AM   #1 (permalink)
buffered
Recruit
 
Join Date: Sep 2008
Posts: 4
buffered is on a distinguished road
code Newbie Question. Seriously lol.

hey guys. wanna take this chance to say hi as well to all of you.

just took up a programming module without ANY programming knowledge and unfortunately this basic programming module is being taught by a lecturer from China. not a single soul in the lecture knows what he's mumbling about.

hoping to learn from u guys here.

We use Vi in our labs. i could use the command gcc in there but couldnt use in in Vim when im home.[ running xp]. well the lab looked like it was using windows xp as well.. weird.

Heres qn 1 which i hope u guys could guide me.

Qn 1. Write a program to approx. the derivative of f(x) = x^2 +0.5x+1 using the half-increment method, in which the derivative of f(x) at a point c is approx by [f(c+h/2) - f(c-h/2)]/h, for small h<0.1. the program takes the values of c and small h from command line and then displays the approx of the derivative of f(x) at c.

here's my coding:
Code:
#include <stdio.h>
#include <stdlib.h>

double f(double x) {
       return x*x+0.5*x+1;}
       
int main(int argc, char *argv[])
       {
           double c,h,ans;
           
           c=atof(argv[1]);
           h=atof(argv[2]);
           
           ans= (f(c+h)/2 - f(c-h)/2)/h ;
           
           printf(" %.3f", ans);
           
           return(0);
}
compiled it successfully. tried to open with ms-dos. gave an error. is there anything wrong with it guys? thanks a mill

and oh, can anyone tell me why we must put a double x in double f(double x)?

thx!

Last edited by redhead; 09-06-2008 at 02:44 PM. Reason: Added [code] - [/code] tags
buffered is offline   Reply With Quote
Old 09-06-2008, 03:01 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Hi Buffered, and welcome here at CN
Quote:
tried to open with ms-dos. gave an error.
You my friend have had your first encounter with the famous Unix/Dos LF/CR indifferencies
Quote:
can anyone tell me why we must put a double x in double f(double x)?
Because otherwise
Code:
0.5*x
would return a warning telling one a conversion choice would have to be made, and depending on the compilers skills it could end up as either
Code:
0*x
or
Code:
1*x
which isn't the behaviour youre looking for, read about Floats vs. integers

If you want to use the same at home as you use on campus, there is mingW which provides Unix like tools for windows aswell as VI for windows

How ever, given that you most likely would delve further into teh usage of a Unix like system, I would suggest you try a Unix like environment like installing Linux under windows
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 09-07-2008, 03:56 PM   #3 (permalink)
buffered
Recruit
 
Join Date: Sep 2008
Posts: 4
buffered is on a distinguished road
thank you so much for ur reply! i'll be reading the links you've provided me with!

turly appreciate it!
buffered is offline   Reply With Quote
Old 09-08-2008, 07:05 PM   #4 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 74
landonmkelsey is on a distinguished road
super easy is LaGrangian interpolation

collocation=approximation passes through given points (x(n) y(n) ) n= 0,1,2

y(x) =

y(0)* (x(1) -x) *(x(2)-x)/(x(1)-x(0)*x(2)-x(0)) + (this term = y(0) at x = x(0)

y(1)*(x(0) -x) *(x(2)-x)/(x(0)-x(1)*x(2)-x(1)) + (this term = y(1) at x = x(1)


y(2)*(x(0) -x) *(x(1)-x)/(x(0)-x(2)*x(1)-x(2)) + (this term = y(2) at x = x(2)

ends up being a parabola
landonmkelsey is offline   Reply With Quote
Old 09-09-2008, 05:21 AM   #5 (permalink)
buffered
Recruit
 
Join Date: Sep 2008
Posts: 4
buffered is on a distinguished road
Quote:
#include <stdio.h>
#include <string.h>

int main(int argc, char*argv[]){

int January_first_day,February_first_day,March_first_d ay,April_first_day,May_first_day,June_first_day,Ju ly_first_day,August_first_day,September_first_day, October_first_day,November_first_day,December_firs t_day;

int i,j,k,l,m,n,o,p,q,r,s,t;

printf("\n January");
printf(" Sun Mon Tue Wed Thu Fri Sat\n");

if (strcmp(argv[1], "Sun") == 0) January_first_day=6; if (strcmp(argv[1], "Mon") == 0) January_first_day=7;
if (strcmp(argv[1], "Tue") == 0) January_first_day=1; if (strcmp(argv[1], "Wed" )== 0) January_first_day=2;
if (strcmp(argv[1], "Thu") == 0) January_first_day=3; if (strcmp(argv[1], "Fri") == 0) January_first_day=4;
if (strcmp(argv[1], "Sat") == 0) January_first_day=5;
for (i = 1; i<=6*January_first_day-2; i = i+1) { printf(" ");} /* print out the first day */
printf("%2d", 1);

for (i=2; i<= 31; i=i+1) {
if ( (i+January_first_day-2)%7 == 0) printf("\n"); /* finish one week */
printf(" %2d ", i); /* insert 4 spaces for format purpose */
}


printf("\n February");
printf(" Sun Mon Tue Wed Thu Fri Sat\n");

if (strcmp(argv[1], "Sun") == 0) February_first_day=3; if (strcmp(argv[1], "Mon") == 0) February_first_day=4;
if (strcmp(argv[1], "Tue") == 0) February_first_day=5; if (strcmp(argv[1], "Wed")== 0) February_first_day=6;
if (strcmp(argv[1], "Thu") == 0) February_first_day=7; if (strcmp(argv[1], "Fri") == 0) February_first_day=1;
if (strcmp(argv[1], "Sat") == 0) February_first_day=2;
for (j = 1; j<=6*February_first_day-2; j = j+1) { printf(" ");} /* print out the first day */
printf("%2d", 1);

for (j=2; j<= 29; j=j+1) {
if ( (j+February_first_day-2)%7 == 0) printf("\n"); /* finish one week */
printf(" %2d", j); /* insert 4 spaces for format purpose */
}
comes out

Quote:
January Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
February Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
the 1st of every month is out of position lol. any idea why. spent the last 6 hrs. its hurting my eyes more then when im cutting onions for my mom.

thx u guys!
buffered is offline   Reply With Quote
Old 09-09-2008, 05:33 AM   #6 (permalink)
buffered
Recruit
 
Join Date: Sep 2008
Posts: 4
buffered is on a distinguished road
umm dunno why it showed up that way, but take it the rest of the dates except the first are out of sync with the rest, hiding away at the left corner
buffered is offline   Reply With Quote
Old 09-09-2008, 06:13 AM   #7 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 74
landonmkelsey is on a distinguished road
try a switch statement to remove the clutter of all those strcmp

clutter can make programs unmanageable

simplicity make programs easier to debug/change

modularity

would help to add a statement stating what the code is trying to do!

pseudo code is a sort of textual flow chart
landonmkelsey is offline   Reply With Quote
Old 09-09-2008, 12:03 PM   #8 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 74
landonmkelsey is on a distinguished road
add a switch statement to eliminate those "strcmp" statements
landonmkelsey is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question - icon code Blucutie All Other Coding Languages 2 05-31-2006 02:32 PM
RSS Code Newbie Feeds sde Code Newbie News 0 03-17-2005 06:35 PM
Newbie, can't not work out what's wrong with this code harker Platform/API C++ 5 12-13-2004 04:21 AM
Would you mind if there were small flash elements at code newbie? sde Lounge 10 05-29-2004 10:05 PM
promoting code newbie sde Lounge 3 02-13-2004 07:54 AM


All times are GMT -8. The time now is 03:59 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting