本文目录一览:
C语言求解
输入的文件为一个字符串,按降幂顺序排列。所以需要的就是提取数字和"^",绝对值不超过1000,意味着申请5位字符串足够。
c语言一元二次方程求系数
矩阵问题:
求出 x1^2 x2^2 x3^2
x1 x2 x3
1 1 1
的逆矩阵,用这个逆矩阵右乘(y1,y2,y2),就分别的a,b,c
C语言算法问题:题目是求二项式系数和:下面是代码:
拿一个具体例子给你看看
unsigned long power(unsigned long, unsigned long);
void cnr(int n, int answer[])
{
//n=3 二进制0000 0011
//1的二进制 0000 0001,左移3位变成0000 1000 ,十进制为8
unsigned long x = (1 n) + 1; /* x=9*/
unsigned long mask = (1 n) - 1; /* mask=7 */
unsigned long result;
int i;
//power计算x的n次方
result = power(x, (unsigned long) n); /* (2^n+1)^n */
for (i = 0; i = n; i++, result = n) /* retrieve data */
answer[i] = result mask;
}
/* ------------------------------------------------------ */
/* FUNCTION power : */
/* This is the function called 'iterative_power' in */
/* file I_POWER.C of this book. */
/* ------------------------------------------------------ */
unsigned long power(unsigned long m, unsigned long n)
{
//n=3,二进制 0000 0011,ox01UL为十六进制无符号,二进制 0000 0001
//第一次循环 0000 00110000 0001=0000 0001,所以符号if条件
//temp*=m,就是temp=temp*n=1*9=9
//m*=m,就是m=m*m=9*9=81
//n=1,就是n=n1,右移1位0000 00111=0000 0001
//剩下循环可以照搬,直到n=0跳出循环
unsigned long temp = 1;
while (n 0) { /* if there exists 1 bits.. */
if (n 0x01UL == 1)/* the right most one ? */
temp *= m; /* YES, the result get a 'm'*/
m *= m; /* anyway, compute m^k */
n = 1; /* throw away this bit */
}
return temp;
}
/* ------------------------------------------------------ */
#include stdio.h
#include stdlib.h
#define MAXSIZE 10
void main(void)
{
int answer[MAXSIZE];
int n, r;
char line[100];
printf("\nFast Combinatorial Coefficient Computation");
printf("\n==========================================");
printf("\n\nN --- ");
gets(line);//输入3
n = atoi(line);//n=3
cnr(n, answer);
printf("\nAll Combinatorial Coefficients :\n");
for (r = 0; r = n; r++)
printf("\nC(%d,%d) = %d", n, r, answer[r]);
}