當前位置:首頁 » 編程軟體 » 輸入格式編程

輸入格式編程

發布時間: 2022-08-31 17:47:12

『壹』 輸入格式為四位正整數,然後轉換成時間格式怎麼用c語言編程

#include<stdio.h>
intmain(intargc,char*argv[])
{
intn;
printf("輸入4位正整數:");
scanf("%d",&n);
printf("%02d:%02d ",n/100,n%100);
return0;
}

不知道我理解的有沒有偏差

『貳』 編程要求從鍵盤按規定的格式輸入時間(時:分:秒)

摘要 #include

『叄』 編程c語言 輸入10個整數 求出其中的最小值 輸入格式如:19 23 12 26 94 9 18

#include<stdio.h>
int main()
{
int i,min=32768;
for (i=1;i<=10;i++)
scanf("%d",&a[i]);
for (i=1;i<=10;i++)
if (a[i]<min) min=a[i];
printf("%d",min);
return 0;
}

『肆』 編程實現: 求3~n之間所有素數之和 示例: 輸入格式:5 輸出格式:8

#include<stdio.h>

int main()

{

int n;

printf("請輸入n:");scanf("%d",&n);

int flag;

int i,j;

int sum=0;

for(i=3;i<=n;i++)

{ flag=0;

for(j=2;j<=i-1;j++)

{


if(i%j==0)

flag=1;


}

if(flag==0&&i!=1)

{

sum=sum+i;

}



}

printf("%d",sum);

return 0;


}

請採納,謝謝支持

『伍』 c++編程 輸入格式是什麼意思

您好,格式字元串的一般形式為:
%[*][輸入數據寬度][長度]類型
其中有方括弧[]的項為任選項
「*」符:用以表示該輸入項,讀入後不賦予相應的變數,即跳過該輸入值。
如:
scanf("%d %*d %d",&a,&b);
當輸入為:1 2 3時,把1賦予a,2被跳過,3賦予b。

『陸』 用C語言編程中,一般的格式是怎樣的

用C語言編程中,一般的格式是怎樣的。
你的問題問得不是很清晰,你具體是在說什麼格式呢?C語言的文件格式其實就是.C啊,如果是編譯過後的,一般就是.obj 或者.exe 或者 .dll 等等。
C語言還有個文件格式是.h。這個是頭文件。

『柒』 C語言編程,輸入是yyyy-month-dd格式的日期 ,求出K天後的日期

/*--------------------------------------------
* FUNC: 日期計算處理函數 CalcDate
* PARA:
* type
* 1: 獲取date1當月的第一天 賦值到date2 其他參數無效
* 2: 獲取date1當月的最後一天 賦值到date2 其他參數無效
* 3: 獲取date1的num天之後的日期 賦值到date2, 當num為負值時獲取date1之前的日期
* 4: 獲取date1的num月之後的日期 賦值到date2, 當num為負值時獲取date1之前的日期
* 若大於月末則賦值月末
* 5: 獲取date1到date2之間的天數 賦值到num, 當date1大於date2時, num為負值
* 6: 獲取date1到date2之間的月數 賦值到num, 當date1大於date2時, num為負值
* 7: 獲取date1的num月之後的月末日期 賦值到date2, 當num為負值時獲取date1之前的月末日期
* 8: 獲取date1的num月之後的日期 賦值到date2, 當num為負值時獲取date1的num月前的日期;若date1為20120229 num為12則date2為20130228
*
* date1: 格式YYYYMMDD, 輸入參數
* date2: 格式YYYYMMDD, 輸入參數/輸出參數
* num: 數字, 輸入參數/輸出參數 可正可負
*
* RETURN VALUE:
* 0: 計算成功
* 非0: 計算失敗
*
* NOTICE: date2作為出口參數時不能是無結束符的字元串的中間欄位
* 因為賦值時將會在date2的後面增加字元串結束符
*
*--------------------------------------------*/
int CalcDate(int type, const char *date1, char *date2, int *num)
{
int Mday[]={29,31,28,31,30,31,30,31,31,30,31,30,31};
int result;
int month;
int yy, mm, dd, yy1, mm1;
char year[4+1], mon[2+1], day[2+1];
EXEC sql BEGIN DECLARE SECTION;
char datebeg[8+1];
char dateend[8+1];
int inputnum;
EXEC SQL END DECLARE SECTION;
result = checkDate(date1);
if ( result != 0 ) return result*10+2;
if ( type == 1 )
{
sprintf(date2, "%6.6s01", date1);
return 0;
}
if ( type == 2 )
{
memset(mon, 0, sizeof(mm));
memcpy(mon, date1+4, 2);
mm = atol(mon);
sprintf(date2, "%6.6s%02d", date1, Mday[mm-LeapFebruary(date1)]);
return 0;
}
if ( type == 3 )
{
memset(datebeg, 0, sizeof(datebeg));
memset(dateend, 0, sizeof(dateend));
memcpy(datebeg, date1, 8);
inputnum = *num;
EXEC SQL select to_char((to_date(:datebeg,'yyyymmdd') + :inputnum),'yyyymmdd') into :dateend from al;
if ( sqlca.sqlcode != 0 ) return sqlca.sqlcode;
memcpy(date2, dateend, 8);
return 0;
}
if ( type == 4 || type == 7 )
{
memset(year, 0, sizeof(year));
memset(mon, 0, sizeof(mon));
memset(day, 0, sizeof(day));
memcpy(year, date1, 4);
memcpy(mon, date1+4, 2);
memcpy(day, date1+6, 2);
yy = atol(year);
mm = atol(mon);
dd = atol(day);
month = yy*12 + mm - 1;
month += *num;
yy = month/12;
mm = month%12 + 1;
sprintf(date2, "%04d%02d%02d", yy, mm, dd);
if ( type == 4 )
{
if ( dd > Mday[mm-LeapFebruary(date2)] )
dd = Mday[mm-LeapFebruary(date2)];
}
if ( type == 7 )
{
dd = Mday[mm-LeapFebruary(date2)];
}
sprintf(date2, "%04d%02d%02d", yy, mm, dd);
return 0;
}
if ( type == 5 )
{
result = checkDate(date2);
if ( result != 0 ) return result*10+4;
memset(datebeg, 0, sizeof(datebeg));
memset(dateend, 0, sizeof(dateend));
memcpy(datebeg, date1, 8);
memcpy(dateend, date2, 8);
EXEC SQL select (to_date(:dateend,'yyyymmdd')-to_date(:datebeg,'yyyymmdd')) into :inputnum from al;
if ( sqlca.sqlcode != 0 ) return sqlca.sqlcode;
*num = inputnum;
return 0;
}
if ( type == 6 )
{
result = checkDate(date2);
if ( result != 0 ) return result*10+7;
memset(year, 0, sizeof(year));
memset(mon, 0, sizeof(mon));
memcpy(year, date1, 4);
memcpy(mon, date1+4, 2);
yy = atol(year);
mm = atol(mon);
memset(year, 0, sizeof(year));
memset(mon, 0, sizeof(mon));
memcpy(year, date2, 4);
memcpy(mon, date2+4, 2);
yy1 = atol(year);
mm1 = atol(mon);
*num = (yy1-yy)*12 + (mm1-mm);
return 0;
}
if ( type == 8 )
{
memset(datebeg, 0, sizeof(datebeg));
memset(dateend, 0, sizeof(dateend));
memcpy(datebeg, date1, LEN_DATE);
inputnum = *num;
EXEC SQL select to_char(add_months(to_date(:datebeg,'yyyymmdd'),:inputnum),'yyyymmdd') into :dateend from al;
if ( sqlca.sqlcode != 0 ) return sqlca.sqlcode;
memcpy(date2, dateend, LEN_DATE);
return 0;
}
}

熱點內容
存儲過程性能優化 發布:2025-02-09 13:42:59 瀏覽:727
源碼失竊 發布:2025-02-09 13:38:34 瀏覽:525
自動瀏覽器腳本 發布:2025-02-09 13:37:00 瀏覽:139
易語言問道源碼 發布:2025-02-09 12:59:03 瀏覽:661
ip和伺服器有關嗎 發布:2025-02-09 12:51:26 瀏覽:950
極光免費腳本 發布:2025-02-09 12:50:33 瀏覽:394
c存儲過程返回結果集 發布:2025-02-09 12:42:00 瀏覽:150
gs哪個配置性價比高 發布:2025-02-09 12:35:57 瀏覽:283
java棧數組 發布:2025-02-09 12:33:37 瀏覽:557
php上傳文件form 發布:2025-02-09 12:33:31 瀏覽:157