C語編程題目
#include<stdio.h>
#include<string.h>
voidsum(char*sum,char*a,char*b)
{
char*s_short,*s_long;
inti_short,i_long,i_result;
i_short=strlen(a)-1;
i_long=strlen(b)-1;
if(i_long>=i_short)
{
s_short=a;
s_long=b;
i_result=i_long+1;
}
else
{
s_long=a;
s_short=b;
i_result=i_short;
i_short=i_long;
i_long=i_result;
i_result++;
}
for(;i_short>=0;i_short--,i_long--,i_result--)
{
sum[i_result]+=s_short[i_short]-'0'+s_long[i_long]-'0';
sum[i_result-1]=sum[i_result]/10;
sum[i_result]%=10;
sum[i_result]+='0';
}
for(;i_long>=0;i_long--,i_result--)
{
sum[i_result]+=s_long[i_long]-'0';
sum[i_result-1]=sum[i_result]/10;
sum[i_result]%=10;
sum[i_result]+='0';
}
if(sum[0])sum[0]+='0';
else
{
i_result=strlen(sum+1);
memmove(sum,sum+1,i_result);
sum[i_result]=0;
}
}
intmain(intargc,char**argv)
{
chara[1001]={0},b[1001]={0},r[1002]={0};
inti,j=0;
scanf("%d",&i);
while(j++<i)
{
memset(r,0,sizeof(r));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%s%s",a,b);
sum(r,a,b);
printf("Case%d: ",j);
printf("%s+%s=%s ",a,b,r);
if(j<i)printf(" ");
}
return0;
}
② C語言編程題目
#include <stdio.h>
char *StrCat(char *s,char *t)
{
int i=0,j=0;
char *s1,*t1;
s1=s;t1=t;
for(;*s1;s1++,i++);
for(;*t1;t1++,j++);
if(i<=j)
{
for(;*t;)*s1++=*t++;*s1='\0';
return s;
}
else
{
for(;*s;)*t1++=*s++;*t1='\0';
return t;
}
}
int main(int argc, char *argv[])
{
char a[100],b[100];
scanf("%s",a);
scanf("%s",b);
printf("%s",StrCat(a,b));
return 0;
}
③ c語言編程題
#include<殲宏stdio.h>
void main()
{
int max,min,sum,i,score[10];
printf("輸入數據:");
for(i=0;i<判畝10;i++)
scanf("%d",&score[i]);
sum = max = min = score[0];
for(i=1; i<10; i++)
{
if(max<掘改森score[i])max = score[i];
if(min>score[i])min = score[i];
sum =sum+score[i];
}
printf("%.2f\n", (sum-min-max)/8.0);
}
④ C語言編程題,求解題思路!
只要按照公式計算每月還款金額就可以了,其中"已歸還本金累計額"等於"貸款本金 除以 還款月數 乘以 已還款月數".
按照題目要求編寫的等額本金還款的C語言程序如下
#include<stdio.h>
int main(){
double P,R,repayment;
int N,i;
scanf("%lf;%d;%lf",&P,&N,&R);
printf("[");
for(i=0;i<N;i++){
repayment=(P/N)+(P-P/N*i)*R;
if(i==N-1)
printf("%.2lf]",repayment);
else
printf("%.2lf,",repayment);
}
return 0;
}