C队列 输出杨辉三角
也是中软笔试的算法题,当时并不知道叫杨辉三角,唉。N年不用了,还得再拾起,为了那个梦。
#include <stdio.h>
void main()
{
int a[50][50];
int i,j,n;
printf("Please input Number:");
scanf("%d",&n);
for (i=0;i<n;i++)
{
for (j=0;j<=i;j++)
{
if (j==0 ||j==i)
a[i][j]=1;
else
a[i][j]=a[i-1][j-1]+a[i-1][j];
printf("%5d",a[i][j]);
}
printf("\n");
}
getch();
}
/*TC 2.0测试*/
#define size 100
#define true 1
#define false 0
typedef int elemtype;
typedef struct queue
{
elemtype element[size];
int front;
int rear;}queue;/*jie gou ti*/
void initqueue(queue*q)
{
q->front=q->rear=0;}/*chu shi hua*/
int enqueue(queue*q,int x)
{
if((q->rear+1)%size==q->front)
return(false);
q->element[q->rear]=x;
q->rear=(q->rear+1)%size;
&nb
相关文档:
[root@localhost test]# hexdump -s 0 -n 52 -C helloworld
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 02 00 03 00 01 00 00 00 10 83 04 08 34 00 00 00 |............4...|
00000020 30 08 00 00 00 00 00 00 34 00 20 ......
1.写出两个函数,分别求两个整数的最大公约数和最小公倍数,用主函数调用这两个函数,并输出结果。两个整数由键盘输入。
#include<stdio.h>
int gcd(int,int);
int lcm(int,int);
int gcd(int m,int n)
{
if(m%n==0)
return n;
else
return gcd(n,m%n);
}
int lcm(int m,int n)
{
return m*n/(gc ......
GCC 编译c程序的方法及过程解析
Justin.zp.Yang 2010.04.10
目前 Linux 下最常用的 C 语言编译器是 GCC ( GNU Compiler Collection ),它是 GNU 项目中符合 ANSI C 标准的编译系统,能够编译用 C 、 C++ 和 Object C 等语言编写的程序。 GCC 不仅功能非常强大,结构 ......
一个很简洁的算法:
void Reverse(char s[])
{
for(int i = 0, j = strlen(s) - 1; i < j; ++i, --j) {
char c = s[i];
s[i] = s[j];
s[j] = c;
& ......
1、选择合适的算法和数据结构
选择一种合适的数据结构很重要,如果在一堆随机存放的数中使用了大量的插入和删除指令,那使用链表要快得多。数组与指针语句具有十分密切的关系,一般来说,指针比较灵活简洁,而数组则比较直观,容易理解。对于大部分的编译器,使用指针比使用数组生成的代码更短,执行效率更高。
在许多 ......