C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 3rd, 2012, 06:33 AM
mritay mritay is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 mritay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 39 m 29 sec
Reputation Power: 0
Help in c

hi, i need to right a prog that calculates sums of geometric series. with the use of function building and declaring...
user enter a number, and it finds all the series that sums up to that number.
example:
31
31 = 1 + 2 + 4 + 8 + 16
31 = 1 + 5 + 25
31 = 1 + 30

no use in math lib.

i've built a working code, but it is only good until 1251.

please help...
:
Code:
int power(int x, int y) /* function that calculates a power number */
{
	int sum;
	for (sum=1; y>0; y--)
		sum*=x;
	return sum;
}
int lg(int base, int x) /*function that finds the power number */
{
	int counter=0, temp=1;
	while (x>temp)
	{
		temp=temp*base;
		counter++;
	}
		return counter;
}
void geometric()
{
	int i=0,j,q=2,n=0,a1=0,num,sum, temp;
	int solution[3][10000];
	for (j=0;j<10000; j++)
	{
		solution[0][j]=0;
		solution[1][j]=0;
		solution[2][j]=0;
	}
	/* first, get the num for the sum of the serie */
	num=get_int();
	/*now, find a1 and a sutiable q and n from a1=1, q=2*/
	for (q=2; q<num; q++)
			for (a1=1; a1<num; a1++)
			{
				temp=(int)(((num*(q-1))/a1)+1);
				n=lg(q,temp);
				sum=(int)((a1*(power(q,n)-1)/(q-1)));
				if (num==sum)
				{
					printf("G");
					solution[0][i]=n;        /* the output is this array */
					solution[1][i]=a1;       /*  which contains in each  */
					solution[2][i]=q;        /*  column n, a1 and q for  */ 
					i++;                     /*         the sum          */
				}
			}
	for (j=0; solution[0][j]!=0; j++)
		printf("a1=%d q=%d n=%d\n",solution[1][j],solution[2][j],solution[0][j]);
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help in c


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap