A. 急求,一個簡單的c語言程序,要求至少60行,要有些知識點,最好是有創意的。
顯示年日歷的程序
1、 main1.cpp文件清單:
#include <iostream.h>
#include "head1.h"
#include <iomanip.h>//setw()函數的頭文件
extern int year;//全局變數
void main()
{
int i;
cout<<"請輸入您要查詢的年份:";
cin>>year;
int n=weekday(year);//調用weekday函數
for(i=1;i<=12;i++)//總共的月份 12
{
int lemp=1;
cout<<endl<<year<<"年"<<setw(27)<<i<<"月"<<endl;
cout<<"-----------------------------------"<<endl;
char weekd[7][20]={"Mon","Tue","Wed","Thu","Fri","Sta","Sun"};//記錄星期一到星期日
for(int j=0;j<7;j++)
cout<<setw(5)<<weekd[j];//setw(5)表示緊跟其後的數據項的輸出佔5個字元寬
cout<<endl<<"-----------------------------------"<<endl;
for(int k=1;k<n;k++,lemp++)//輸入每月第一天的起始位置,用空格補充
cout<<setw(5)<<" ";
int m=monthday(i);//調用monthday函數
for(int d=1;d<=m;d++,lemp++) //輸出每月的天數
{
cout<<setw(5)<<d;
if(lemp==7) //控制一行輸出到星期天,如果到星期天則重新計數
{
cout<<endl;
lemp=0;
}
}
n=lemp%7; //當輸出完一個月後,記錄這個月的最後一天在哪,尋找下個月的
if(n==0) //第一天的起始位置
n=7;
cout<<endl<<"-----------------------------------"<<endl<<endl<<endl;
}
}
2、isl.cpp文件清單:
#include <iostream.h>
int isleapyear(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;//閏年返回值為1
else
return 0;
}
3、weekday.cpp文件清單:
#include <iostream.h>
int weekday(int year)
{
int n=year-2007;//已知2007年的元旦剛好是星期一
n=n+(n-1)/4+1;// 判斷,以每年52個整星期計算該年比2007年多出來的天數
n=n%7;
if(n==0)
return 7; //返回輸入的年份的元旦是星期幾
else
return n;
}
4、monthday.cpp文件清單:
#include <iostream.h>
#include "head1.h"//需要調用head1中的函數
int year;
int monthday(int i)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
return 31;
else if(i==2)
{
if(isleapyear(year)==1)//調用isleapyear函數
return 29;
else return 28;
}
else return 30;
}5、head1.h文件清單:
int isleapyear(int year);//函數原型聲明
int weekday(int year);//函數原型聲明
int monthday(int i);//函數原型聲明
B. C語言70行程序,在線求。要簡單點的。最好附上解釋說明該函數什麼作用
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#defineLIM_LEN30
voidbad_exit(void);
/*-----十六進制字元串轉化為十進制-------chapter2_2.3---------------*/
/*-------首先定義一個返回值為int型的冪函數pow1-------*/
intpow1(intm,intn)
{
inti;
intx=1;
for(i=0;i<n;i++)
{
x*=m;
}
returnx;
}
/*-------首先定義一個返回值將十六進制轉化為int型的函數htoi-------*/
inthtoi(chars[])
{
intn,m,i;
intcount=0;
intmzs=0;//控制冪函數的指數
charc;
intch[LIM_LEN];
enummark{NO,YES};//定義標記符號
enummarkflag;
i=0;
n=strlen(s);//字元串的長度,屬於string.h頭文件庫中
//printf("n=%d ",n);
if(s[i]=='0')//除去字元串中的0X或者0x
{
i++;
if(s[i]=='x'||s[i]=='X')
{
i++;
}
}
//printf("i=%d ",i);
//printf("%d ",i);
flag=YES;
//printf("%d ",YES);
for(i,m=0;i<n&&flag==YES;i++)//將字元串轉化為相應的十六進制數字並放入一個int數組中
{
c=s[i];
if(isdigit(c))
{
ch[m]=s[i]-'0';
}
elseif(c>='a'&&c<='f')
{
ch[m]=s[i]-'a'+10;
}
elseif(c>='A'&&c<='F')
{
ch[m]=s[i]-'A'+10;
}
else
{
flag=NO;
atexit(bad_exit);//參數為函數指針,雖然在內部定義但是還需要在文件中函數聲明,要不就是錯誤
exit(EXIT_FAILURE);//參數EXIT_FAILURE和EXIT_SUCCESS
//puts("theinputisn't0-9ora-f!");//列印但是會計算一個溢出錯誤值,上述方法可避免
}
m++;
}
//printf("i=%d ",i);
//printf("m=%d ",m);
m=m-1;//m多計數一次,需要退回一次--------------->每次一定考慮是否多計數!!!
for(m;m>=0;m--)//累加來求出int型的值
{
count+=ch[m]*pow1(16,mzs);
mzs++;
}
returncount;
}
/*-------錯誤退出注冊函數給atexit()使用-------*/
voidbad_exit(void)
{
puts("theinputisn't0-9ora-f!");
}
/*-------首先定義一個返回值將十六進制轉化為int型的函數htoi的驅動函數-------*/
voidhtoi_test()
{
intcount;
charn_nums[]="0X12a";//298
count=htoi(n_nums);
printf("%d ",count);
}
/*-----十六進制字元串轉化為十進制-------chapter2_2.3------over---------*/
C. c語言程序詳解
while(a<15)a++; 出循環時a為15
while(b++<15); b++為後加,當b為15是退出循環,之後因為b++,所以b還會再自加1變為16
所以結果即為15,16
D. 大家幫忙看看c語言程序,最好寫上每行注釋
#include<stdio.h>// 系統函數
#include<time.h>//時間函數
#define MAX 32 //定義函數MAX=32
long queen[MAX]={0},queenl = 1; // 長數組queen MAX內元素為全零,queenl 這個函數為1
int count =0,label = 0;//整形 函數 定義數值
FILE *txt; 文件格式
void Answers(long row, long ml, long mr)
無返回值函數(long是一種數字的格式,有long short double float)
{
if(row != queenl)//條件
{
long pos = queenl & ~(row|ml|mr);同時滿足兩個條件下 pos等於這個結果
while(pos)//循環
{
long p = pos & -pos;// p等於同時正負pos,也就是說,怎麼說好呢,你就理解為它是一個無法滿足的條件,使之變成0,因為只有0是+-一體的
pos-=p; // pos=pos -p
Answers(row|p, (ml|p)>>1, (mr|p)<<1);
}
}
else
count++; count= count +1
}
void Answersp(int n,long row, long ml, long mr)//同理
{
if(row != queenl)
{
long pos = queenl & ~(row|ml|mr);
while(pos)
{
long p = pos & -pos;
pos-=p;
int i = 0;
while(p>>i)i++; //當滿足p>>0時 i=i+1,但是注意這句話有點問題,你少了一對大括弧,循環語句沒有循環的范圍,這樣的話循環的只有queen【n】=i這句話
queen[n] = i;
Answersp(n+1, row|p, (ml|p)>>1, (mr|p)<<1);
queen[n] = 0;
}
}
else
{
count++;
for(int j=0; j<label; j++)
fprintf(txt,"%d.",queen[j]);//出指令printf(「 「)是格式
fprintf(txt," ");
if(count%3 == 0)fprintf(txt,"\n");
}
}
int main()main函數,程序主體
{
double f,f1; 定義雙精度浮點函數
char print= 'n' ,flag; 字元函數
printf("請輸入1~32的之間的整數:"); 輸出
while(label == 0 || label <= 1 || label >= 32) 同時滿足三個條件執行循環,這個循環,其實就是流文件讀取確保裡面有東西
{
scanf("%d",&label); 讀入
while((flag = getchar()) != 10);
這句循環條件2 steps| 1) flag = grther() 2) flag所獲得的值不能等於10
if(label <= 0 || label <= 1 || label >= 32)
printf("非法輸入!\n請輸入1~31的之間的整數:\n");
}
printf("將%d皇後的解輸出到answer.txt?(Y確定,任意鍵繼續)\n",label);
scanf("%c",&flag);
print = flag;
while(flag != 10)flag = getchar();
printf("程序計算中,所需時間依問題規模而定,請耐心等待....\n");
for(int i=1; i<label; i++) 循環
queenl=1+(queenl<<1);
if(print == 'y' || print == 'Y')
{
if((txt=fopen("answer.txt","w"))==NULL) fopen是流文件讀取
printf("answer.txt文件打開出錯!\n");
else
{
f=time(NULL); null是系統函數,似乎是空值,這個記不清了,很多年沒編輯C了,忘了
Answersp(0, 0, 0, 0);
f1=time(NULL);
f1 = f1-f;
fprintf(txt,"\n==%d問題的解總數有%d種==\n",label,count);
fprintf(txt,"用時%d分%d秒\n",(int)(f1/60),(int)((int)f1%60));
fclose(txt);流文件讀取關閉
}
}
else
{
f=time(NULL);
Answers(0, 0, 0);
f1=time(NULL);
f1 = f1-f;
printf("\n==%d問題的解總數有%d種==\n",label,count);
printf("用時%d分%d秒\n",(int)(f1/60),(int)((int)f1%60));
}
printf("Program end.\nPress Enter key to exit!");
while((flag = getchar()) != 10);
}
大概的進行了標注,相同格式的語句就沒有重復標記,希望你能理解
E. C語言程序設計,求各行程序的含義和意思,答辯用的,蟹蟹大佬
C語言實現簡單的翻譯功能
2018年04月25日 16:48:30火炎焱燚OOK閱讀數 3813
題目描述:編寫一個程序,依次輸入英文與漢語拼音,輸入兩個「 * 」表示輸入結束,再輸入一段英語句子,列印出其對應漢語拼音。
要求:不得使用<string.h>頭文件
題目中要求不得使用<string.h>提醒我們使用其中的函數來編寫代碼,不過函數的實現需要自己來思考,根據自己的需要可以調整原函數的功能。思路大致是:輸入完畢後拿原結構體記錄的英文內容與 a 中的單詞逐個相比,若相同,則輸出結構體中對應的漢語拼音。
#include <stdio.h>#include <stdlib.h>#define M 100struct tran //建立結構體,將英文與對應的漢語拼音存儲在一起{char English[M];char Chinese[M];}n[M];int my_strlen(char a[]); //聲明自定義測量數組長度的函數int my_strcmp(char* str1,char* str2); //聲明自定義判斷兩個字元串是否相同的函數int main(){int i=1,j,k;char a[M],*p=a;printf("請首先輸入英文,然後輸入漢語拼音: ");while(n[i-1].English[0]!='*'||n[i-1].Chinese[0]!='*') //當輸入兩個「 * 」時輸入終止{printf("請輸入第%d組 ",i);scanf("%s%s",n[i].English,n[i].Chinese);i++;}printf("請輸入一個句子 ");getchar(); //接收上一個回車,避免下一個scanf()無法輸入scanf("%[^ ]",a);for(i=0;a[i]!='