Write a program to read in two numbers, x and n, and then compute the sum of this geometric progression: 1+x+x2+x3+………….+xn.

Program Code:
#include<stdio.h>
#include<math.h>
void main()
{
int x,n,sum=0,i;
L:printf("\n enter the value of x and n: ");
scanf("%d%d",&x,&n);
if(x<0 || n<0)
{
printf("\n enter only positive values for x and n");
goto L;
}
for(i=0;i<=n;i++)
{
sum=sum+pow(x,i);
}
printf("\n x=%d,n=%d,sum of G.P=%d",x,n,sum);
getch();
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: