?? work1.cpp
字號(hào):
// work1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "iostream.h"
#define MAX_N 25
struct point_type
{
double x;
double y;
double weight;
}point[MAX_N];
int main(int argc, char* argv[])
{
int n;
int i;
static double u11,u12,u21,u22,c1,c2;
double a,b;
//
//輸入數(shù)據(jù)的個(gè)數(shù)
cout<<"輸入點(diǎn)個(gè)數(shù)n:"<<endl;
cin>>n;
//確認(rèn)輸入的數(shù)在正確輸入范圍
while ((n>MAX_N)||(n<0))
{
cout<<"輸入點(diǎn)個(gè)數(shù)必須在范圍 1 到"<<MAX_N<<endl;
cout<<"重新輸入n:";
cin>>n;
}
//輸入數(shù)據(jù)
cout<<"輸入x_i,y_i,weight_i,i=0.."<<n-1<<": "<<endl;
for (i=0;i<n;i++)
{
cin >>point[i].x>>point[i].y >>point[i].weight;
}
cout<<"輸出x_i,y_i,weight_i,i=0.."<<n-1<<": "<<endl;
for (i=0;i<n;i++)
{
cout<<point[i].x<<" "<<point[i].y <<" "<<point[i].weight<<endl;
}
//方程組的求解
u11=u12=0;
u22=0;
c1=c2=0;
for (i=0;i<n;i++)
{
u11=u11+point[i].weight;
u12=u12+point[i].weight*point[i].x;
u22=u22+point[i].x*point[i].x*point[i].weight;
c1=c1+point[i].y*point[i].weight;
c2=c2+point[i].x*point[i].y*point[i].weight;
}
u21=u12;
//求出線性函數(shù)系數(shù)
a=(c1*u22-c2*u12)/(u11*u22-u12*u21);
b=(c1*u21-c2*u11)/(u21*u12-u22*u11);
cout<<"解為 p(x):"<<a<<"+"<<b<<"x"<<endl;
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -