[ create a new paste ] login | about

Link: http://codepad.org/6dKDfthn    [ raw code | output | fork | 2 comments ]

C, pasted on Sep 14:
#include<stdio.h>
#include<conio.h>
float tong(float, int);
float luythua(float, int);

float luythua(float x, int n)
{
	float t = 1;
	for(int i = 1; i <= n; i++)
	{
		t = t * x;
	}
	return t;
}

float tong(float x, int n)
{
	float s = 0;
	for(int i = 1; i <= n; i++)
	{
		s = s + luythua(x, i);
	}
	return s;
}

int main()
{
	int n;
	float x;

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

	printf("\nNhap x: ");
	scanf("%f", &x);

	float ketqua = tong(x, n);
	printf("\nTong: %f",ketqua);

	getch();
	return 0;
}


Output:
1
2
3
4
5
Line 17: error: conio.h: No such file or directory
In function 'luythua':
Line 9: error: 'for' loop initial declaration used outside C99 mode
In function 'tong':
Line 19: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments:
posted by ntdung1001 on May 14
from Ptit with love.

reply
posted by yonnon on Aug 1
#include<bits/stdc++.h>

using namespace std;
int main()
{
int n;
int x;
cout << "Enter x: ";
cin >> x;
cout << "Enter n: ";
cin >> n;
int sum;
for (int i = 0; i <= n; ++i)
{
sum += pow(x,i);
}
cout <<sum<<
endl;
return 0;
}
reply