원주율 구하기 프로그램

cppig1995의 이미지

#include <stdio.h>
#include <conio.h>

#define MAXDIGIT 2503

void divide_longnum_by_int( int x[], int y, int z[] )
{
long dividend;
int quotient;
long remainder;
int i;
remainder = 0;
for (i = 0; i < MAXDIGIT; i++) {
dividend = remainder * 10000L + x[i];
quotient = dividend / y;
remainder = dividend % y;
z[i] = quotient;
}
}

void multiply_longnum_by_int( int x[], int y, int z[] )
{
long sum;
long carry;
int i;

carry = 0;
for (i = MAXDIGIT - 1; i >= 0; i--) {
sum = (long)x[i] * y + carry;
z[i] = sum % 10000;
carry = sum / 10000;
}
}

void add_longnum( int x[], int y[], int z[] )
{
int carry, sum;
int i;
carry = 0;
for (i = MAXDIGIT - 1; i >= 0; i--) {
sum = x[i] + y[i] + carry;
z[i] = sum % 10000;
carry = sum / 10000;
}
}

int longnum_is_zero( int x[] )
{
int i;
for (i = MAXDIGIT - 1; i >= 0; i--) {
if (x[i] != 0)
return 0;
}
return 1;
}

void print_longnum( int x[] )
{
int i, count;

printf("%d.", x[0]);

count = 1;
for (i = 1; i < MAXDIGIT - 2; i++) {
printf("%04d", x[i]);
}
}

void set_longnum_to_int( int x[], int n )
{
int i;

x[0] = n;
for (i = 1; i < MAXDIGIT; i++) {
x[i] = 0;
}
}


int main()
{
int a[MAXDIGIT];
int pi[MAXDIGIT];
int i, j;

clrscr();

set_longnum_to_int( pi, 2 );
set_longnum_to_int( a, 2 );

for (i = 1, j = 3; ! longnum_is_zero( a ); i++, j += 2) {
multiply_longnum_by_int( a, i, a );
divide_longnum_by_int( a, j, a );
add_longnum( pi, a, pi );
}

gotoxy(1, 5);
printf("Value of PI ( %4d digit ) =", MAXDIGIT);
gotoxy(1, 7);
print_longnum( pi );
printf("\n");

getch();

return 0;
}
File attachments: 
첨부파일 크기
Image icon f8615f3816d774fb80a84914b92638c0.png1.69 KB
Plain text icon pi500.txt1.95 KB
Forums: 
puzzlet의 이미지

이게 더 간단한 것 같은데요? :twisted:

 p 410p 120p 130p  v
v01+1*2\*g00*::::+1<
>g:00p*+10p::*20g*v
vp03+*p02:g03+1*2\<$
>00g20g/ :10g30g/ -|
^^v**25%g02g00,+"0"<
^ >00p10g30g%52**10p

P.S. 일부 인터프리터에서는 자리수 제한이 있으며, PyFunge에서 돌리면 제대로 돌아갑니다.
댓글 첨부 파일: 
첨부파일 크기
Image icon 0바이트

발발다빠따반반나다발딸발발다빠따따맣발발다뿌
멓터벅더떠벋떠벌더벌벌떠벌떠더법벍떠더벌벌떠

codebank의 이미지

자유 게시판보다는 강좌나 팁에 가까운것 같아서 게시물을 옮겼습니다.
:)

------------------------------
좋은 하루 되세요.

hey의 이미지

명예의 전당으로 갈 조짐이 보입니다. ..


----------------------------
May the F/OSS be with you..


cppig1995의 이미지

Python 에다 재귀라면 인터프리터는 재귀의 깊이를 제한할 겁니다.

그리고 Redirection 과 함께 하면,

나오는 내용은 첨부로...

[수정] 죄송합니다.

그냥 올렸더니 한 줄로 나타난 소수점 약 2000자리 수치, 초소형 스크롤바, 망가진 빠른 답장 양식이 보이는군요.

댓글 첨부 파일: 
첨부파일 크기
Plain text icon 0바이트

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.