代码引自优快云论坛:http://bbs.youkuaiyun.com/topics/390608383
1:mujiok2003九九乘法表是个不变的,何必用变量。
int main()
{
char const* const tbl = "1×1=1\n"
"1×2=2 2×2=4\n"
"1×3=3 2×3=6 3×3=9 \n"
"1×4=4 2×4=8 3×4=12 4×4=16\n"
"1×5=5 2×5=10 3×5=15 4×5=20 5×5=25\n"
"1×6=6 2×6=12 3×6=18 4×6=24 5×6=30 6×6=36\n"
"1×7=7 2×7=14 3×7=21 4×7=28 5×7=35 6×7=42 7×7=49\n"
"1×8=8 2×8=16 3×8=24 4×8=32 5×8=40 6×8=48 7×8=56 8×8=64\n"
"1×9=9 2×9=18 3×9=27 4×9=36 5×9=45 6×9=54 7×9=63 8×9=72 9×9=81";
puts(tbl);
return 0;
}
2:
vrace这个应该能满足你的要求...
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a;
for (a = 0x11; a < 0xa0; a++)
{
for (a = (a & 0xf0) + 1; (a & 0x0f) <= ((a & 0xf0) >> 4); a++)
{
printf("%dx%d=%d\t",
(a & 0x0f),
(a & 0xf0) >> 4,
((a & 0xf0) >> 4) * (a & 0x0f));
}
a += 0x10;
printf("\n");
}
return 0;
}
3: mujiok2003 都是常量,没有变量。
#include <stdio.h>
void mtable_helper(int const n, int const i)
{
if(i > n)
{
printf("\n");
}
else
{
printf("%dx%d=%d ", i, n, i *n);
mtable_helper(n,i+1);
}
}
void mtable(int const n)
{
if(0 == n) return;
mtable(n-1);
mtable_helper(n,1);
}
int main()
{
mtable(9);
return 0;
}
4: jha334201553我是不是可以说一个变量都没用?
#include <stdio.h>
int main(int argc, char* argv[])
{
__asm {
xor eax,eax
mov esi,1
mov edi,esi
label1:
cmp esi,edi
jle la_next
}
printf("\n");
__asm {
inc edi
mov esi,1
cmp edi,0xA
je la_exit
la_next:
mov eax,edi
imul esi
push eax
push edi
push esi
}
printf("%dx%d=%-2d ");
__asm
{
add esp,0x0C
inc esi
jmp label1
la_exit:
}
return 0;
}
5:jha334201553编译器内部有一大堆的全局变量都可以用,还有各种头里面也有很多结构体可以用,一个变量,,哈哈哈哈哈哈,你为难谁
#include <stdio.h>
#include <time.h>
int main()
{
struct tm p;
for (p.tm_hour=1; p.tm_hour<=9; p.tm_hour++)
{
for(p.tm_min=1; p.tm_min<=p.tm_hour; p.tm_min++)
{
printf("%dx%d=%-2d ", p.tm_min, p.tm_hour, p.tm_min*p.tm_hour);
}
printf("\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
template <int x> struct line {
static void print(int m) {
line<x-1>::print(m);
printf("%dx%d=%d\t",x,m,m*x);
}
};
template <> struct line<1> {
static void print(int m) {
printf("1x%d=%d\t",m,m);
}
};
template <int m,int n> struct table {
static void print() {
table<m-1,n-1>::print();
printf("\n");
line<n>::print(m);
}
};
template <> struct table<1,1> {
static void print() {
printf("1x1=1\t");
}
};
int main(void)
{
table<9,9>::print();
printf("\n");
return 0;
}
7:
jha334201553只要MOD_VALUE是大于10的数,这个代码都成立,代码那是何其多啊
#include <stdio.h>
#define MOD_VALUE 15
int main(int argc, char* argv[])
{
int a;
for (a=1; a%MOD_VALUE<=9; a++)
{
for (a=a%MOD_VALUE+MOD_VALUE; a/MOD_VALUE<=a%MOD_VALUE; a+=MOD_VALUE)
{
printf("%d+%d=%-2d ", a/MOD_VALUE, a%MOD_VALUE, (a%MOD_VALUE)*(a/MOD_VALUE) );
}
printf("\n");
}
return 0;
}
8: amoyman问题是:这种题目有意思吗?///注:只是这个程序的运行结果和平常的相反,但是也满足条件
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i < 81; i++)
{
if((i / 9) <= (i % 9))
printf("%d*%d=%2d ", (i / 9) + 1, (i % 9) + 1, ((i / 9) + 1) * ((i % 9) + 1));
if (i % 9 == 8)
{
printf("\n");
}
}
return 0;
}
运行结果图: