Cậu #include <math.h> chưa ?
Hì, trước e dùng borland C++, nay chuyển sang visual c++ 6.0
Vừa mới buổi đầu chuyển sang mà thầy đã bắt làm cái calculator rùi, hiện tự mầy mò nghiên cứu thì tạm tạm ổn, nhưng còn chức năng sqrt (tính căn bậc 2 thì vướng mắc!).
Bro nào chỉ giáo dùm với, e cần biết cách gọi hàm toán học từ các thư viện như math.h, stdlib.h
Ví dụ:
Bình thường ở C++ đơn thuần thì chỉ cần đường dẫn thư viện math.h và gọi hàm với cú pháp :
1. hàm sqrt : sqrt ( A );
2. hàm pow : pow ( A, B );
Nhưng khi vô dùng visual c++ 6.0 thì nó báo lỗi:
error C2065: 'sqrt' : undeclared identifier
Bro nào gỡ rối giúp e chút, trước kia dùng toàn lệnh c++, giờ sang cái này hơi khác chút,...
=====================================
XWAYSTYLE ---------> Brings joy to milions.....
Intel(R) Pentium 4(R) 2.8GHz Main IntelD845Pemy (Socket 478) RAM 1024Mb VGAFX5200 128Mb 128Bit HDD Maxtor 160Gb PATA Sound Blaster live 5.1 Gamer
Windows Vista Ultimate Sp1 (activated)
Rating : 2.5 Mark
Theme: Windows Aero (very nice!)
Cậu #include <math.h> chưa ?
C++ Code:
#include<cmath> #include<iostream> using namespace std; int main() { system("cls"); int param=1024,result; result=sqrt(param); system("pause"); return 0; }
http://www.cplusplus.com/reference/clibrary/cmath/
Một ví dụ nhỏ về hàm sqrt của MSDM
Visual C++ Code:
/* SQRT.C: This program calculates a square root. */ /* double sqrt( double x ); */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main( void ) { double question = 45.35, answer; answer = sqrt( question ); if( question < 0 ) printf( "Error: sqrt returns %.2f\n", answer ); else printf( "The square root of %.2f is %.2f\n", question, answer ); }
Code:Output The square root of 45.35 is 6.73
Đã được chỉnh sửa lần cuối bởi Forlorn_hope : 17-08-2008 lúc 11:49 AM.
Không biết ghi gì luôn ...