¿ª·¢ÓïÑÔ¤ÎC - C/C++ / CÓïÑÔ
¼ÆËã1-1/2+1/3-1/4+¡+1/99-1/100+¡,Ö±µ½×îºóÒ»ÏîµÄ¾ø¶ÔֵСÓÚ10-4Ϊֹ¡£
¿ª·¢ÓïÑÔ¤ÎC
ÆÈËÂ𣡲»ÒªÔÚÕâÑùÁË¡£
ÄãµÄÌâºÜ¼òµ¥µÄ£¬¿ÉϧÎÒ²»»á¡£
²»»á£¬²»»á£¬¾ÍÊDz»»á¡£
¸ßÊÖ°ï棺http://topic.csdn.net/u/20100514/22/a0306fbb-4006-49d3-b339-c3ef8eb347aa.html
¤ÎCÊÇʲô£¿CÓïÑÔÊÇÕâÑùµÄ...
C/C++ code:
/*¼ÆËã1-1/2+1/3-1/4+¡+1/99-1/100+¡,Ö±µ½×îºóÒ»ÏîµÄ¾ø¶ÔֵСÓÚ10-4Ϊֹ¡£*/
#include <stdio.h>
#include <math.h>
int main(void)
{
float sum=0,n=1,i=1;
while(fabs(i/n)>1e-4)
{
sum += i/n;
n++;
i = -i;
}
printf("%f\n",sum);
return 0;
}
ÎÒÓеãÔÎÔεĸоõ
[code=C/C++][/code]
#include <iostream>
using namespace std;
void main()
{
int i=1;
double m,sum;
while(m> =10e-4)
{
if(i%2==0)
{m=1/i;sum=sum-m;}
else
{m=1/i;sum=sum+m;}
i++;
}
cout < <sum < <endl;
}
ÊÇC++³ÌÐò£¬Äã×Ô¼º¸Äһϰ¡
ÕæÊÇÎêÈèÁË¿ª·¢¶þ×Ö°¢
Â¥Ö÷Õâ¸ö¼òµ¥µÄ£¬£¬Â¥Ö÷ºÃºÃ¶¯¶¯ÄÔ½î
¿´ÁËÕâ¸öÌâ¾õµÃ¸Ã¸´Ï°Ò»Ï¸ߵÈÊýѧÁË
Ïà¹ØÎÊ´ð£º
ÈçÌ⣬C/C++ÖеÄexeclÔõôµ÷ÓÃдºÃµÄjava³ÌÐò£¬
execl("/opt/java1.5/bin/java","MyClass",NULL);
ÕâÑùµÄ²»ÐÐŶ¡£
²»»á.
ÔËÐÐjava³ÌÐò
ÕÒ¹¤¾ß²é¿´Ò»ÏÂÄǸö³ÌÐòµÄÃüÁîÐÐ
ËÑË÷Ï£ºjni ......
ÓÐÒ»10*10¾ØÕ󣬳ýÈ¥µÚÒ»¸öµã£¨0£¬0£©ºÍ×îºóÒ»µã£¨9£¬9£©£¬»¹Óа˸öµãΪ1£¬ÆäËû¶¼Îª0£¬ÒªÇóÓöþάÊý×é±íʾ¡£°Ë¸öµãÊÇËæ»úÉú³ÉµÄ£¬±àдÏà¹Ø³ÌÐò±íʾ¾ØÕóËùÓпÉÄÜÇé¿ö¡£
ÕæÐÄÇó½Ì¸÷λ¸ßÊÖ£¬°¥£¡±¾ÈËÌ«²ËÁË£¡ºÇºÇ£¡
......
´ó¼ÒºÃ£º
ÎÒÏëʵÏÖ¼ì²âµ½²åÈëSD¿¨ºó×Ô¶¯½«SD¿¨¸ñʽ»¯µÄ¹¦ÄÜ£¬²»ÖªC/C++ÖÐÓÐûÓиñʽ»¯UÅ̵ĺ¯Êý£¿
ÁíÍ⣬ÎÒ²»ÏëʹÓÃSHFormatDrive£¬ÒòΪÕâ¸öº¯Êý»áµ¯³öÊÇ·ñÒª¸ñʽ»¯µÄÌáʾ¿ò£¬ÎÒÐèÒªµÄÊÇϵͳ×Ô¶¯¸ñʽ»¯£¬¶ø²Ù×÷Õß² ......
ÔÚ¸ùĿ¼/libÖдæ·ÅÒ»¸ölog.c£¬log.h£¬²¢ÓÃÏÂÃæµÄÓï¾ä£º
gcc -c log.c
ar crv liblog.a log.o
±àÒë³öÒ»¸öliblog.a¾²Ì¬¿â£¬È»ºóÔÚÎļþ¼Ð£º/testfileÖд´½¨Ò»¸ötest.cºÍtestc.c£¬test.cÖÐÒýÓÃÁËtestc.cÖж¨ÒåµÄ·½·¨ ......