[ create a new paste ] login | about

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

C++, pasted on Apr 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream> 
#include <math.h> 

int main () 
{ 
double x = -1, dx = 0.25, y; 
std::cout << "x: " << "\ty: " << std::endl; 
while (x <= 1.5) { 
y = sin(x) - pow(x, 2) + 2/x; 
if (!x) 
std::cout << x << "\t-" << std::endl; 
else 
std::cout << x << "\t" << y << std::endl; 
x += dx; 
} 

return 0; 
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
x: 	y: 
-1	-3.84147
-0.75	-3.91081
-0.5	-4.72943
-0.25	-8.3099
0	-
0.25	8.1849
0.5	4.22943
0.75	2.78581
1	1.84147
1.25	0.986485
1.5	0.0808283


Create a new paste based on this one


Comments:
posted by svetkrikun2012 on Dec 3
#include <iostream.h>
usinq namespace std;

void main (){
int i, N;
double S, A, B;
cin >>N;
S=0; A=1; B=1;
for (i=1; i<=N; i++){
A1=0.8*A+0.1*B;
B2=0.6*A+0.2*B;
S=S+A;
A=A1;
B=B1;
}
cout <<S<< end;
}
reply