(本代碼目的是將輸入的字符換成后面第四個字母,China——>Glmre,前面那段代碼是并列執行的,便于讓各位看到結果的差異,即口Glmre)
問題描述:
當獨立執行第二段代碼時輸出:Glmre
當和第一段代碼并列執行時輸出:口Glmr
#include <math.h>
#include <stdio.h>
int main(void)
{
//以下為并列的代碼,不是主要問題
{
printf("hw 3.2\n");
float way,temp;
printf("請輸入金額:\n");
scanf("%f",&temp);
printf("請輸入存款方式(1-5):\n");
scanf("%f",&way);
if(way==1)
{
temp*=(1+5*0.03);
printf("result= %f \n\n",temp);
}
else if(way==2)
{
temp*=(1+2*0.021);
temp*=(1+3*0.0275);
printf("result= %f \n\n",temp);
}
else if(way==3)
{
temp*=(1+3*0.0275);
temp*=(1+2*0.021);
printf("result= %f \n\n",temp);
}
else if(way==4)
{
temp*=pow(1.015,5);
printf("result= %f \n\n",temp);
}
else
{
temp*=pow(1+0.0035/4,20);
printf("result=%f \n\n",temp);
}
}
//以下為提問的代碼
{
printf("hw 3.6\n");
printf("請輸入五位數密碼:\n");
char c[5];
int i;
for(i=0;i<5;i++) //for回圈輸入多個字符
{
c[i]=getchar(); //將輸入的字符賦給變數
}
for(i=0;i<5;i++)
{
c[i]=c[i]+4; //將輸入的字符換成后面第四個
c[5]='\0';
putchar(c[i]);
}
putchar('\n');
}
}
請大家幫忙看看是哪的問題,謝謝!
uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/266792.html
標籤:C語言
上一篇:求助!【PAT】01-復雜度2 Maximum Subsequence Sum (25 分)一個測驗點怎么也過不去!
