c语言实现
Ⅰ 积分在c语言里怎么实现
include<stdio.h>
#include<math.h>
double integ(double a,double b)
{
double s,x,h;
int n=100,i;
h=fab(b-a)/n;
s=(sin(a)+sin(b))/2.0;
for(i=1;i<=n-1;i++)
{
x=a+i*h;
s=s+sin(x);
}
s=s*h;
return s;
}
main()
{
double s;
s=integ(0.0,0.15);
printf("s=%f\n",s);
}
你自己跑下,可能有语法错误。
Ⅱ C语言可以实现什么
C语言本事很大
操作系统几乎都是C语言写的
WINDOWS,LINUX...下的几乎所有程序也可以用C语言来写
只是单纯用C来调用API来写WINDOW图形界面的程序比较麻烦
但C功能强大,与底层契合也好 精通C的话用来提高自己能力不错
Ⅲ C语言如何实现
#include <stdio.h>
#define N 10
int main() {
int a[N];
int i;
printf("请输入10个整数:");
for(i=0;i<N;i++)
{
scanf("%d ", &a[i])
}
for(i=0;i<N;i++)
{
if (a[i]%2 == 0)
printf("%d ", a[i])
}
return 0;
}
Ⅳ 用c语言实现下列要求
# include <stdio.h>
int main( )
{
int i;
double bonus,bon1,bon2,bon4,bon6,bon10;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+100000*0.05;
bon6=bon4+100000*0.03;
bon10=bon6+400000*0.015;
printf("请输入当月利润i:");
scanf("%d",&i);
printf("i=%d\n",i);
if(i<=100000){
bonus=i*0.1;
}else if(i<=200000){
bonus=bon1+(i-100000)*0.075;
}else if(i<=400000){
bonus=bon2+(i-200000)*0.05;
}else if(i<=600000){
bonus=bon4+(i-400000)*0.03;
}else if(i<=1000000){
bonus=bon6+(i-600000)*0.015;
}else{
bonus=bon10+(i-1000000)*0.01;
}
printf("奖金总数为:%10.2f\n",bonus);
return 0;
}
【答题不易,请采纳谢谢】
Ⅳ c语言实现简单函数
#include "stdio.h"
#include "string.h"
int fun(char s[],char max[])
{
char ss[100][100],*p=s;
int i=0,j=0,k,n=0;
while(*p!='\0')
{
if((*p)!=' ')
{
ss[i][j]=*p;
j++;
}
else
{
ss[i][j]='\0';
i++;j=0;
}
p++;
}
ss[i][j]='\0';
strcpy(max,ss[0]);
n=n=strlen(max);
for(k=1;k<=i;k++)
{
if(strlen(ss[k])>strlen(max))
{
strcpy(max,ss[k]);
n=strlen(max);
}
}
return n;
}
int main()
{
char s[100];/*asdf asdfll asdf*/
char max[100];
int n;
gets(s);
n=fun(s,max);
printf("%s,%d",max,n);
}
Ⅵ C语言编程实现
所有转换
一个函数实现
原来贴的有点问题
改了
#include<stdio.h>
#define size 64
void transform(int n1,char c[size],int n2)
{
int a[size]={0},j,i=0;
long int num=0;
if(n1>10)
{
while(c[i])
{
if(c[i]>='0'&&c[i]<='9')
num=num*n1+c[i++]-48;
else if(c[i]>='A'&&c[i]<='Z')
num=num*n1+c[i++]-55;
else if(c[i]>='a'&&c[i]<='z')
num=num*n1+c[i++]-87;
else
{
puts("error\n");
return;
}
}
i=0;
}
else
while(c[i])
{
if(c[i]<'0'||c[i]>'9')
{
puts("error\n");
return;
}
num=num*n1+c[i++]-'0';
}
i=0;
while(num!=0)
{
a[i++]=num%n2;
num/=n2;
}
printf("(%s)%d转换为:\n(",c,n1);
if(n2<10)
{
for(j=i-1;j>=0;j--)
printf("%d",a[j]);
printf(")%d\n",n2);
}
else
{
for(j=i-1;j>=0;j--)
if(a[i]>=10)
printf("%c",a[j]+55);
else
printf("%d",a[j]);
printf(")%d\n",n2);
}
}
main()
{
int n1,n2;
char c[size]={0};
do
{
puts("输入现在数的进制类型:\n");
scanf("%d",&n1);
puts("输入需要转换的数据:\n");
scanf("%s",c);
puts("输入目标数的进制类型:\n");
scanf("%d",&n2);
transform(n1,c,n2);
puts("输入y继续,按任意键退出:\n");
getchar();
}while(getchar()=='y');
}
这个程序有错误提示
还有好可以实现16进制之内的任意进制数的相互转换
我真不想拿上来
如果不明白
留言
必回
Ⅶ 数据结构的c语言实现
typedef struct LNode{
int data;
struct *next;
}LNode,*LinkList;
里面定义有问题,struct *next;-改成 ----struct LNode *next;
CreateList_L
p->next=(int)malloc(sizeof(LNode));类型为什么要强转,还匹配吗?p->next=(LinkList)malloc(sizeof(LNode));
这段代码问题太多了,建议把链表这好好看看
Ⅷ 设计算法,并用c语言实现。
#include<stdio.h>
intchange(intamount,intindex,intconstcoins[]){
if(amount==0)return1;
if(index<=0)return0;
for(inti=amount/coins[index-1];i>=0;--i){
if(change(amount-i*coins[index-1],index-1,coins)){
if(i)
printf("%d*%d",i,coins[index-1]);
return1;
}
}
return0;
}
intmain()
{
intcoins[]={20,50};
intconstsize=sizeof(coins)/sizeof(int);
intamount;
for(inti=0;i<size;++i){
for(intj=i+1;j<size;++j){
if(coins[i]>coins[j]){
inttemporary=coins[i];
coins[i]=coins[j];
coins[j]=temporary;
}
}
}
if(coins[0]<=0){
printf("数据有误,零钱必须大于0 ");
return-1;
}
printf("请输入要兑换的货币金额:");
scanf("%d",&amount);
if(change(amount,size,coins))
printf(" 兑换成功 ");
elseprintf(" 兑换失败 ");
return0;
}
Ⅸ 用c语言实现
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i;
char a[4]={'1','2','3','4'};
char b[4];//严格讲,转为二进制时,b的存储空间不够,但可以运行,只是不能再超范围修改,这样定义是不安全的,建议扩大数组b的大小。
i=atoi(a);
printf("%d\n",i);
itoa(i,b,2);
printf("%s\n",b);
}
Ⅹ c语言的实现
#include<stdio.h>
#include<malloc.h>
#define NULL 0
struct node
{
int data;
struct node *next;
};
struct node *head,*head_a;
struct node *create()
{
struct node *tail, *p;
int x;
head=tail=NULL;
printf("\n请输入一个整数:\n");
scanf("%d",&x);
while(x!=0)
{
p=(struct node *)malloc(sizeof(struct node));
p->data=x;
p->next=NULL;
if(head==NULL)
head=tail=p;
else
{
tail->next=p;
tail=p;
}
printf("\n请输入一个整数:\n");
scanf("%d",&x);
}
return(head);
}
struct node *unite(struct node *a,struct node *b)
{
struct node *ha;
ha=head_a;
while(ha->next!=NULL)
ha=ha->next;
ha->next=head;
return(a);
}
void sortf()
{
struct node *p;
int temp;
L: p=head_a;
p=head_a;
while(p->next!=NULL)
{
if(p->data>p->next->data)
{
temp=p->data;
p->data=p->next->data;
p->next->data=temp;
}
p=p->next;
}
p=head_a;
while(p->next!=NULL)
{
if(p->data>p->next->data)
{
goto L;
}
p=p->next;
}
// return(a);
}
void main()
{
struct node *A,*B,*C,*LA;
printf("\n请输链表A的值,以0结束:\n");
LA=head_a=A=create();
printf("\n请输链表B的值,以0结束:\n");
B=create();
/////////////////////////////
printf("\n链表A的值:\n");
while(LA!=NULL)
{
printf("%d\t",LA->data);
LA=LA->next;
}
C=unite(A,B);
printf("\n链表B的值:\n");
printf("\n");
while(B!=NULL)
{
printf("%d\t",B->data);
B=B->next;
}
printf("\n链表C的值:\n");
printf("\n");
LA=head_a;
while(LA!=NULL)
{
printf("%d\t",LA->data);
LA=LA->next;
}
printf("\n");
printf("\n经过排序后链表C的值:\n");
printf("\n");
sortf();
LA=head_a;
while(LA!=NULL)
{
printf("%d\t",LA->data);
LA=LA->next;
}
printf("\n");
}
几经波折才算搞清楚..弄出来了!!!!!!!!!!!!!!!