求一份IS31FL3206的程序(求一道C语言程序月份题!)
求一道C语言程序月份题!
#include<iostream>
#include<string>
using namespace std;
char *date[7]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int day,year,mon,d,i;
while(scanf("%d",&day),day!=-1){
i=day%7;
year=2000,mon=0,d=0;
if(day>=146097){
year+=day/146097*400;
day%=146097;
}
if(day>=36525){
day-=36525;
year+=100;
year+=day/36524*100;
day%=36524;
}
if(year%400&&day>=1460) {
day-=1460;
year+=4;
}
year+=day/1461*4;
day%=1461;
if(!(year%400)||!(year%4)&&(year%100)) {
if(day>366) {
year++;
day-=366;
year+=day/365;
day%=365;
}
if(year%4) month[1]=28;
else month[1]=29;
}
else{
year+=day/365;
day%=365;
month[1]=28;
}
for(mon =0;mon<12;mon++){
if(day<month[mon]) {d=month[mon];break;}
else day-=month[mon];
}
if(mon>11) year++,mon=0;
printf("%d-%02d-%02d %s\n",year,mon+1,day+1,date[i]);
}
return 0;
}
是类似这样的么??
求一份C语言程序
#include<stdio.h>
int main()
{
char num[100] = "\0";
char a[100] = "\0";
char oth[100] = "\0";
char s[100];
char *p1 = num;
char *p2 = a;
char *p3 = oth;
int i = 0;
gets(s);
while(s[i]!='\0')
{
if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))
{
*p2 = s[i];
p2++;
}
else if(s[i]>='0'&&s[i]<='9')
{
*p1 = s[i];
p1++;
}
else
{
*p3 = s[i];
p3++;
}
i++;
}
printf("%s\n",num);
printf("%s\n",a);
printf("%s\n",oth);
return 0;
}
c语言 求解 这题的答案是-31 详细过程
1、主函数执行时 a=-13 if为真 所以输出一个“-” 此时a=13 进入fun函数
2、第一次执行fun函数 13%10=3 所以此时输出 “3” 进入if判断 此时a被重新赋值 a=13/10=1
1!=0 if条件为真 再次进入fun函数
3、由于a=1 所以此时输出 “1” 进入if判断 此时a被重新赋值 a=1/10=0 if条件为假 返回主函数 执行完毕
所以 按顺序显示结果为:-31
谁能帮我解释一下这个程序?为什么结果等于31?
#include <stdio.h>
main()
{
int a=0,i;
for(i=1;i<5;i++)
{
switch(i)
{
case 0:
case 3:a+=2;
case 1:
case 2:a+=3;
default:a+=5;
}
}
printf("a=%d\n",a);
}
计算步骤:
i=1,走case 1:没break,下面都会执行,a+=3;此时a=3,执行a+=5,a=8
i=2,走case 2:a+=3;此时a=11,执行a+=5,a=16
i=3,走case 3:a+=2;此时a=18,执行a+=3,a=21,执行a+=5,a=26
i=4,走default:a+=5,执行a+=5,a=31