[ create a new paste ] login | about

Link: http://codepad.org/kVjBYYWr    [ raw code | output | fork | 1 comment ]

C, pasted on Aug 17:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i, n;
	float x, T, S;
	i = 0;
	T = 1;
	S = 0;
	printf("\nNhap x: ");
	scanf("%f", &x);

	printf("\nNhap n: ");
	scanf("%d", &n);

	while(i < n)
	{
		T = pow(x, (2 * i + 1));
		S = S + T;
		i++;
	}

	printf("\nTong la %f",S);

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by incarnation16 on May 22
#include <stdio.h>

int main()
{
int n;
do
{

printf("Enter n: ");
scanf("%d", &n);

} while (n < 1);

int x;
printf("Enter x: ");
scanf("%d", &x);

int sum = x;
int p = x;

for (int i = 1; i < n; i++)
{
p = p * x * x;

sum = sum + p;
}
printf("Sum = %d", sum);
}
reply