조건 출력 질문

익명 사용자의 이미지

int coo_coo(int start, int end, int dan)
{
 int i,j,k=0;
 
 for(j=1; j<=9; j++)
 {
  for(i=start; i<=end; i++)
  {
   printf("%d * %d = %d\t",i,j,i*j);
   k++;
   if(k==dan)
   {
    printf("\n");
    k=0;
    break;
   }
  }
 }
 
 return 0;
}

구구단을 출력하는 함수입니다.
start부분에는 시작 단, end부분에는 끝 단, dan부분에는 몇단씩 끊을것인지의 숫자입니다.
제가 원하는 것은
시작 단: 3단 끝 단 : 5단 나타날 단 : 2
이렇게 했을때

3*1=3 4*1=4
3*2=6 4*2=8
.... ....
3*9=27 4*9=36

5*1=5
5*2=10
....
5*9=45

이렇게 나타내고 싶습니다.
하지만 위와 같은 소스로 했을경우 5단은 나오지 않고 4단까지만 나오네요.
소스가 난잡하지만 다른 방법이나 해결책좀 말씀해주세요

snowall의 이미지

i*j, (i+1)*j, ..., (i+dan)*j
i*(j+1), (i+1)*(j+1), ..., (i+dan)*(j+1)
...
(i+dan+1)*j, (i+dan+2)*j, ... , (i+dan+dan)*j
...

이런 식으로 나오면 되겠군요.

for(k=start;k+=dan;k<=end){
  for(j=1;j++,j<=9){
    for(i=k,i++,i<=dan){
      print(i*j)
    }
   print("\n")
  }
}

이런 구조로 짜면 될 것 같은데요.

테스트 해 보진 않았습니다..

피할 수 있을때 즐겨라! http://melotopia.net/b

kalevala의 이미지

짜고나니 snowall 님의 것과 같네요 :( 늦었군요.

int coo_coo(int start, int end, int dan)
{
    while(start <= end){
        for(int i=1; i<=9; i++){
            for(int j=0; j<min(dan, end-start+1); j++){
                printf("%d * %d = %d\t", start+j, i, (start+j)*i);
            }
            puts("");
        }
        start += dan;
    }
    return 0;
}
익명 사용자의 이미지

:( 늦었군요. 54분이나.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.