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

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 04-06-2005, 04:21 PM   #1 (permalink)
akshay19
Registered User
 
Join Date: Apr 2005
Posts: 3
akshay19 is on a distinguished road
Need Help with C programming - I am new to C/C++

I have specified code below and I am looking for more efficient code. Can someone help me out? Appreciated all your help. Thank you.

Contact information: akshay_shah@ameritech.net
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

main()
{
	double Myval = 0.0;
	Myval = BusyWork(3.0, "qwertyuiopasdfghjklzxcvbnm");
	printf("Myvalue: %d16.2\n", Myval);
}


BusyWork(double dInit, char* pszKey)
{
int i;
short j, k;
double dVal = dInit;
double dTemp;

	if (dInit <=0.0)
	return 0.0;
	for (i = 0; i<1000000; i++)
	{
	 for (j=0; j<10; j++)
	 {
	  dTemp = (double)(i*4);
	  if (j%2)
 	 	dVal += dVal * 0.1;
	  else
	  	dVal -= dVal * 0.1;
	  dVal /= dInit;
	  dVal -= ((double)j * 2.2) + 1.0;
	  dVal += ((double)j * 1.5) + 1.0;
	  for (k = 0; k<(short)strlen(pszKey); k++)
	  {
	   dVal += (double)(pszKey[k] - (char)k);
	   dTemp += 0.1;
	  }
	   dVal += dTemp;
	   dVal += sin((double)(j % 4) * 90.0);
	 }
	}
dVal += BusyWork(dInit - 1.0, pszKey);
return dVal;
}

Last edited by Valmont; 04-06-2005 at 05:28 PM.
akshay19 is offline   Reply With Quote
Old 04-07-2005, 05:23 AM   #2 (permalink)
destin
Java Junkie
 
destin's Avatar
 
Join Date: Mar 2005
Posts: 40
destin is on a distinguished road
Does this program compile for you?
destin is offline   Reply With Quote
Old 04-07-2005, 05:35 AM   #3 (permalink)
akshay19
Registered User
 
Join Date: Apr 2005
Posts: 3
akshay19 is on a distinguished road
Yes it does compile and works for me, but it is runs for 2 to 3 min to complete. I want to make it more efficient so that it runs quickly. Appreciate if you come up with something better. Thank you.
akshay19 is offline   Reply With Quote
Old 04-07-2005, 07:59 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
Just add a predifinition of the BussyWork() and it will compile.
Now to the real question, I've tried a few things, but since you have that 1000000 times loop it dosn't seem like theres much to improve, altho the reverse calling of the function is taking some extra time. But what exactly is it supposed to do ? if that was any cleare there might be some shortcuts elsewhere, than just all this number crunching.
__________________
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 04-07-2005, 10:21 AM   #5 (permalink)
akshay19
Registered User
 
Join Date: Apr 2005
Posts: 3
akshay19 is on a distinguished road
Good Question. I was only give psuedocode, but don't know what they are trying to acheive with this short program. Well I am going to work on some alternate logic and verify start time and end time of execution, which ever is shorter I will pick on and post here. Meanwhile if you or anyone finds alternate way of doing then please go ahead and post it here. Thank you for all your help.
akshay19 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
Comparison of Different Programming Languages Punch-M6.net All Other Coding Languages 23 04-19-2007 01:34 PM
Implementing Run Length Encoding on Bitmaps in C Programming kodonovan_cork Standard C, C++ 0 04-21-2004 10:23 AM
For those who have Learned C from "The C Programming Lanuage" DemosthenesB Standard C, C++ 5 07-13-2003 12:22 AM
edit? anon Lounge 10 11-21-2002 03:02 PM


All times are GMT -8. The time now is 11:45 AM.


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