, , sin(x) <math.h> setw(10) <iomanip>. ? , - - . ++ , . .
, , :
1. :
_ _ ( );
_ , ( ), ( ), , ( );
2. ;
3. .
main(), , main(). main() .
main() . 4.
. 4 main()
main() . 5.
. 5 main()
, , .. . .
, - . - , .. , . . , . , , .. . , , , . , . . 6.
. 6
, sin(x) <math.h>, , , . , double. sin(x) :
double sin(double x){
double res;
res=...; //
return res; // ,
}
double res, (res result ). . res , , . return res; .
|
|
sin(x) main() :
z=sin(1.5);
. . , . , . , , . . :
double function(double a, double b){...}
:
int main(){
double x, y, z1, z2, z3;
x=10;
y=-0.3;
z1=function(x,y); //
z2=function(1.8, y); //
z3=function(1.8, 0); //
return 0;
}
.
1. .
. 7.
. 7 1
.. , double. , kv. , double.
kv:
double kv(double x){
double res;
res=x*x;
return res;
}
:
2. x, Z -1≤ ≤2 1.
. Z (x). double, .. . , double x. . main() .
:
// test.cpp: .
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
double fz(double x){
double res;
if(x<1){
res=x+3.0;
}
else {
res=4.0*x;
}
return res;
}
int main(){
double x, z;
cout<<setw(10)<<"x"<<setw(10)<<"z"<<endl;
for(x=-1; x<=2; x=x+1){
z=fz(x);
cout<<setw(10)<<x<<setw(10)<<z<<endl;
}
return 0;
}
:
3. x, y, Z -1≤ ≤0,5 1, 5≤ y ≤15 5.
. Z (x). double, .. . , double x, double y. . main() .
|
|
:
// test.cpp: .
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
double fz(double x, double y){
double res;
if(x*y<1){
res=x+y;
}
else {
res=x-y;
}
return res;
}
int main(){
double x, y, z;
cout<<setw(10)<<"x"<<setw(10)<<"y"<<setw(10)<<"z"<<endl;
for(x=-1; x<=0.5; x=x+1){
for(y=5; y<=15; y=y+5){
z=fz(x, y);
cout<<setw(10)<<x<<setw(10)<<y<<setw(10)<<z<<endl;
}
}
return 0;
}
:
4. 1≤ n ≤10 1.
. Z (n). double, .. . , int n. . main() n .
:
// test.cpp: .
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
double fz(int n){
double res;
int i;
res=0;
for(i=1; i<=n; i=i+1){
res=res+1.0/i;
}
return res;
}
int main(){
int n;
double z;
cout<<setw(10)<<"n"<<setw(10)<<"z"<<endl;
for(n=1; n<=10; n=n+1){
z=fz(n);
cout<<setw(10)<<n<<setw(10)<<z<<endl;
}
return 0;
}
:
5. 5 5 .
. print_mass. , , double [5][5]. , . , void, . . main() A[5][5], B[5][5] print_mass .
:
// test.cpp: .
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
void print_mass(double x[5][5]){
int i, j;
for(i=0; i<5; i=i+1){
for(j=0; j<5; j=j+1){
cout<<setw(10)<<x[i][j];
}
cout<<endl;
}
}
int main(){
double A[5][5], B[5][5];
int i,j;
for(i=0; i<5; i=i+1){
for(j=0; j<5; j=j+1){
A[i][j]=2.3*i+j;
B[i][j]=i-1.5*j;
}
}
cout<<"massiv A:"<<endl;
print_mass(A);
cout<<"massiv B:"<<endl;
print_mass(B);
return 0;
}
:
6. [5][5] [i][j]=0,3i-j, B[5][5] B[i][j]=i-1.5j. .
. , sum_pol. x[5][5]. main() A B, sum_pol.
:
// test.cpp: .
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
double sum_pol(double x[5][5]){
int i, j;
double s;
s=0;
for(i=0; i<5; i=i+1){
for(j=0; j<5; j=j+1){
|
|
if(x[i][j]>0){ s=s+x[i][j];}
}
}
return s;
}
int main(){
double A[5][5], B[5][5], sa, sb;
int i,j;
for(i=0; i<5; i=i+1){
for(j=0; j<5; j=j+1){
A[i][j]=0.3*i+j;
B[i][j]=i-1.5*j;
}
}
sa=sum_pol(A);
cout<<"s A>0 = "<<sa<<endl;
sb=sum_pol(B);
cout<<"s B>0 = "<<sb<<endl;
return 0;
}
:
:
, fstream. .
:
1. ?
2. , ?
3. *.xls?
4. ?
5. , , ?
:
1. , :
2. - Z (x, y)=5,5 x -2,8 y 0≤ x ≤1 0,2; -2≤ y ≤0 0,8. , *.txt, *.xls.
3. X(15) , ; . X(15) . , *.xls.
4. - 20 . : , .
5. 3 .
6. (10) . . . . : .