---
title: "{面试}九九乘法表"
author: "beefcow"
date: "2010-06-07T17:07:24Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-06-07T17:13:32Z"
id: 686192
url: "https://beefcow.iteye.com/blog/686192"
---

看到这样一篇讲面试题的文章:

[http://pengcqu.iteye.com/blog/504628](http://pengcqu.iteye.com/blog/504628)

 

第一题 是 打印九九乘法表,没什么难度,因为大概不过就是如此而已:

```
#include <stdio.h>
int main(){   
    int i,j;
    for(j=1;j<=9;j++){
        for(i=1;i<=j;i++){
            printf("%d*%d=%d ",i,j,i*j);                 
        }
        printf("\n");
    }
    getchar();
    return 0;
}
```

 

两层循环.

 

不过瞄了一下代码,给出的只有一层循环,第一眼还没看明白怎么回事,跑一遍才晓得,原来如此,也算是另一种思路吧:

```
#include <stdio.h>
int main(){   
    int i,j;
    //only go to print the second line when i meets j,
    //otherwise,keep the value of j,and only raise i.
    for(i=1,j=1;j<=9;i++){
        printf("%d*%d=%d ",i,j,i*j);
        if(i==j){
            i=0;
            j++;
            printf("\n");
        }
    }
      getchar();
      return 0; 
} 
```

 

主要是让j憋住,直到i追上来,才j++,i赋0，打印下一行.

留个纪念.

 

 ps.我发现JavaEye上不好的一个趋势,老有IT男弄张MM的照片当头像,相当无语.