Monday, 13 December 2010

Algorithm for To read in two numbers x and n and then compute the sum of this geometric progression 1+x+x2+x3+……….+xn

Description:


In this program we have to read the two numbers and the calculate the sum of this geometric progression in above mention .

Algorithm:


Step 1: Start
Step 2: read values of x and n, sum=1, i=1
Step 3: check for n & X
i)             if n<=0 || x<=0
ii)            print values are not valid
iii)                           read values of x and n Step 4: perform the loop operation

i)             for(i=1;i<=n;i++) then follows
ii)            sum=sum+pow(x,i)
Step 5: print sum
Step 6: Stop



Output:

1.Enter the values for x and n:2 3
Value is valid Sum of series=15

2.Enter the values for x and n:4 9
Value is valid Sum of series=21845
  3.Enter the values for x and n:01
 Value is not valid

Conclusion: the program is error free

VIVA QUESTIONS:

1) what is the difference between structures and unions ?
Ans: Here the major difference is with in the structure all elements must be allocated memory. But in union highest memory allocation must be allocated to all these elements.





c programs

No comments:

Post a Comment