#include<stdio.h>
int main(){
int tra(int n);
int i,n,add = 0;
scanf("%d",&n);
printf("∑di=%d\n",tra(n));
return 0;
}
int tra(int n){
int item=n,add=0;
while(item > 0){
add += item % 10;
item /= 10;
}
return add;
}
#include<stdio.h>
int main(){
char **fre(char str[],int n);
char str[20];
int i;
gets(str);
char **p = fre(str,20);
for(i=0;*((char *)p+i*2)!='\0';i++){
printf("字母%c出现的次数:%d\n",*((char *)p+i*2),*((char *)p+i*2+1));
}
}
char **fre(char str[],int n){
int i,j,m=0,sign;
char **fre = (char **)malloc(n*sizeof(char *));
for(i=0;i<2;i++)
fre[i] = (char *)malloc(2*sizeof(char));//这两步是申请一个n * 2大小的二维空间
for(i=0;str[i]!='\0';i++){
sign = 0;
if(str[i]>='a' && str[i] <= 'z'){
for(j=0;j<=m;j++){
if(*((char *)fre+j*2) == str[i]){
*((char *)fre+j*2+1) = *((char *)fre+j*2+1)+1;
sign = 1;
break;
}
}
if(sign == 0){
*((char *)fre+m*2) = str[i];
*((char *)fre+m*2+1) = 1;
m++;
}
}
}
*((char *)fre+m*2) = '\0';
return fre;
}
3、高精度计算两个长整数的乘积,两个数用数组存放。
#include<stdio.h>
#include<math.h>
#define N 100
#define M 200
int main(){
intA[N]={0,5,2,3,6,7,3};//3763250
intB[N]={0,9,0,1};//1090
intC[N];
inti,na,nb,n;
for(na=N-1;na>=0;na--)
if(A[na]!=0)break;
for(nb=N-1;nb>=0;nb--)
if(B[nb]!=0)break;
if(na> nb) n = na;
elsen = nb;
for(i=0;i<=n;i++){
C[i]=C[i]+ A[i]+B[i];
C[i+1]= C[i] / 10;
C[i]= C[i] % 10;
}
if(C[n+1]!=0)n=n+1;
printf("restultis:");
for(i=n;i>=0;i--)
printf("%d",C[i]);
}
#include<stdio.h>
#include<math.h>
#define N 100
#define M 200
int main(){
doublef(double x);
doublei,j,k,fi,fj,fk;
i=0;
j=2;
fi= f(i);
fj= f(j);
while(fabs(fi-fj)> 1e-3){
k= (i + j)/2;
fk= f(k);
if(fk*fi<0){
j= k;
fj= f(j);
}elseif(fk*fj<0){
i= k;
fi= f(i);
}
}
printf("f(x)的解为:%.4f\n",i);
}
double f(double x){
return3*x*x*x-5*x-6;
}
int main(){
Queue* que = CreateQueue(); //创建一队列
struct tree *root,*p;
int i,j;
root = creat();
p = root;
AddQ(que,p);
//每次遍历,找出左右孩子都是叶子的节点,并将此节点变为叶子,值为运算结果
//多次遍历,直到这个树只剩下根节点
printf("%c\n",root->right->symbol);
while(root->left->symbol!='v' || root->right->symbol!='v'){
//层次遍历
printf("1111");
while(que!=NULL){
p = DeleteQ(que);
if(p->symbol!='v') {
if((p->left->symbol=='v')&&(p->left->symbol=='v')){
if(p->symbol=='+')
p->value = p->left->value + p->right->value;
else if(p->symbol=='-')
p->value = p->left->value - p->right->value;
else if(p->symbol=='*')
p->value = p->left->value * p->right->value;
else if(p->symbol=='/')
p->value = p->left->value / p->right->value;
p->symbol='v';
}else{
if(p->left!=NULL) AddQ(que,p->left);
if(p->right!=NULL) AddQ(que,p->right);
}
}
}
}
printf("%d",root->value);
}
这道题没太看懂
#include<stdio.h>
#include<math.h>
#define LEN sizeof(struct node)
struct node{
int value1;
int value2;
struct node *next;
};
/*创建一个如例图的链表*/
struct node *creat(void){
struct node *p1,*p2,*p3;
p1=(struct node *)malloc(LEN);
p2=(struct node *)malloc(LEN);
p3=(struct node *)malloc(LEN);
p1->value1 = 3;
p1->value2 = 3;
p2->value1 = -5;
p2->value2 = 1;
p3->value1 = 6;
p3->value2 = 0;
p1->next=p2;
p2->next=p3;
p3->next=NULL;
return(p1);
}
int main(){
struct node *p;
int x,fx=0,n,An;
scanf("%d",&x);
p = creat();
while(p!=NULL){
An = p->value1;
n = p->value2;
fx = fx + An * pow(x,n);
p=p->next;
}
printf("f(x)=%d\n",fx);
}