Jump to content

C: Problem with solving problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
rakche

rakche

    Newbie

  • Members
  • Pip
  • 4 posts
I am new in programing on C. Everything was fine until this project. I have this homework and I dont know where to start. I know that I must use two or three times for or while but I dont know where and how to start solving this problem.

Posted Image

I have function s with int x and n. Input for x-maximum, x-minimum, n - number of seqences and dx for number of loops - moves in array.:confused: ... Please help... Thanks in advance :rolleyes:

#2
Buttacup

Buttacup

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Anyway looking at that it is pretty basic but I for one am not clear on what the prerequisites are. What outcome are you trying to achieve? At any rate the equation resolves to a for loop if you need to sum values of s in a number of intervals you can wrap that in another for. If you are looking for a change in something well that wouldn't require any looping but more so some math BEDMAS I do believe unless it's ds/dx you are looking for. You could translate the Spanish for us may help us help you. I would give an example but it's homework right and I dare not :D

#3
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
As the person above me said, its not clear what you need to do. Define the problem first. If you just need to calculate the s value for some SPECIFIC value of x, you can rearrange the expression by looking at it as a sum of (1+x) and x^i. The second sum is of course a geometric series, the formula for which you can find in Wikipedia. Otherwise you will have to translate whatever is written there to English...

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Since x and n are known in advance, this is just a for loop with a sum in the middle.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
rakche

rakche

    Newbie

  • Members
  • Pip
  • 4 posts
First of all, thanks for help. I appreciate that very much. :thumbup:

Translate of image is (sorry for that - its is in serbian by the way):
Make a table of function s for every Xmax=>X=>Xmin with step dx. (function s is in image above).
From standard input user give us: n (exponent of x), xmin (x minimum), xmax (x maximum) and dx (step).

For example if user puts:
n=2
xmin=1
xmax=3
dx=1

Calculating:
S(1)=(1+1+1^1)+(1+1+1^2)=6
S(2)=(1+2+2^1)+(1+2+2^2)=12
S(3)=(1+3+3^1)+(1+3+3^2)=20

Output Result:
x=1 s=6
x=2 s=12
x=3 s=20

I supose that if user puts:
n=2
xmin=1
xmax=3
dx=3

Calculating:
S(3)=(1+3+3^1)+(1+3+3^2)=20

Output Result:
x=3 s=20

I done this so far...:thumbdown:
#include <stdio.h>
#include <math.h>

main()
{
	double x,xMIN,xMAX,dx,sum,;
	int ExponentMax,ExponentStart;

	printf("Enter xMin: ");
	scanf("%lf",&xMIN);

	printf("Enter xMax: ");
	scanf("%lf",&xMAX);

	printf("Enter dx: ");
	scanf("%lf",&dx);

	printf("Enter exponent of integer x: ");
	scanf("%d",&ExponentMax);
	ExponentMax=1;
		for (x=xMIN;x<=xMAX;x+=dx)
		{
		printf("X: %.2f\n",x);
			for (ExponentMax=1;ExponentStart<=ExponentMax;ExponentStart++)
			{
				ExponentStart*=x;
				sum=1+x+pow(x,ExponentStart);
			
			}
		printf("Sum: %.2f\n",sum);
			
		}


}


#6
Buttacup

Buttacup

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Dobro! Ti problema?? Aside from for(ExponentMax=1; <==== ?????? And why with the ExponentStart*=x;? I think you are missing a += in there too! Make that two if you need the sum of sums! Dober Dan!

#7
rakche

rakche

    Newbie

  • Members
  • Pip
  • 4 posts
I dont get it. When I change that code I got same results for all integers (x).? Dobro vece :) Mine biggest problem here is with exponent of x... I dont get it how to make them go x^n on every sum.

#8
i6472

i6472

    Newbie

  • Members
  • Pip
  • 4 posts
What my friend is trying to ask is simple hot to write in c formula for each sum of x when you have exponent in each sum,witch goes from i to n ?

#9
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
whats the role of the dx parameter?

#10
i6472

i6472

    Newbie

  • Members
  • Pip
  • 4 posts
role of Dx is step which X takes to move between values of Xmin and Xmax

#11
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
Stupid me ><. Then just use the formula for geometric series sum.

#12
i6472

i6472

    Newbie

  • Members
  • Pip
  • 4 posts
whats the formula ? please write in C languange