c语言小设计(全文520字)

c语言写情话


//需求:输入年月日,输出第几天

#include <stdio.h>

#include <time.h>

int main(void) {

struct tm ts = {};

scanf("%d%d%d", &ts.tm_year, &ts.tm_mon, &ts.tm_mday);

  ts.tm_year -= 1900;

  --ts.tm_mon;

    time_t tn = mktime(&ts);

ts = *localtime(&tn);

  printf("第%d天\n", ts.tm_yday + 1);

  return 0;

    }

//需求: 设计程序从键盘输入一组非负数,输入负数时结束输入。输出这组非负数的个数、最大值,及最大值的序数。

#include <stdio.h>

#define N 2020

int main(){

int sum=0,i=1,x,max=1;

int s[N];

printf("请输入:");

scanf("%d",&x);

while(x>0){

s[i++]=x;

sum++;

scanf("%d",&x);

}

for(i=1;s[i]!='\0';i++){

if(s[i]>s[max])

max=i;

}

printf("%d %d %d",sum,s[max],max);

return 0;

}

//需求:输入一个数,输出这个数的位数并逆序输出

#include <stdio.h>

int length(int n1){

int c;

if(n1/1000>=1){

c=4;

}

else{

if(n1/100>=1){

c=3;

}

else{

if(n1/10>=1){

c=2;

}

else{

c=1;

}

}

}

return c;

}

void nixu(int n1){

for (; n1 > 0; n1 /= 10)

    printf("%d", n1%10);

}

int main(){

int n1,c,n2;

scanf("%d",&n1);

c=length(n1);

printf("%d",c);

printf("\n");

nixu(n1);

return 0;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容