求大神将下面的c语言改成能在Matlab上运行的!急!急!
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/17 12:15:02
求大神将下面的c语言改成能在Matlab上运行的!急!急!
#include
intdays[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
char s[8][10] ={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
bool is_leap(int year)
{
return (year%4==0 && year%100) || (year % 400 == 0);
}
int DateToInt(int year,int mon,int day)
{
int ans=0,t=is_leap(year) ? 1 : 0 ;
for(int i=1 ; i
#include
intdays[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
char s[8][10] ={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
bool is_leap(int year)
{
return (year%4==0 && year%100) || (year % 400 == 0);
}
int DateToInt(int year,int mon,int day)
{
int ans=0,t=is_leap(year) ? 1 : 0 ;
for(int i=1 ; i
程序如下,已经做子函数处理,所以请放在一个m文件中运行:
function [] = myhelp()
clear;
clc;
week = ['Monday ';'Tuesday ';'Wednesday';'Thursday ';'Friday ';'Saturday ';'Sunday '];
week = cellstr(week);
%printf('Input the date (eg 2013 10 21 , -1 ends the input):\n');
year = input('Input year:');
mon = input('Input month:');
day = input('Input day:');
myday = DateToInt(year,mon,day);
cxd = mod(myday+6,7);
disp('six days later is:')
disp(week(cxd))
function myday = DateToInt(year,mon,day)
days =[31,28,31,30,31,30,31,31,30,31,30,31;31,29,31,30,31,30,31,31,30,31,30,31];
myday = 0;
t = is_leap(year);
for ii = 1:year-1
myday = myday + is_leap(ii)*366+(1-is_leap(ii))*365;
for jj = 1:mon-1
myday = myday + days(t+1,jj);
end
end
myday = myday + day;
function isleap = is_leap(year)
isleap = (mod(year,4)==0 && mod(year,100)~=0) || (mod(year,400)==0) ;
实例:
Input year:2013
Input month:10
Input day:22
six days later is:
'Monday'
有问题可以追问
copyright (c) cxd1301
再问: 同学,这个matlab我学了没多久,学习 C 有一些时间了,matlab语言有什么特点啊,如果我想编一个程序的话,用C还有点眉目,可用Matlab就不懂了,,求大神赐教!!
再答: 会C的话会matlab就很快了,matlab用C内核,主体还是C++的东西,其语言其实是类C语言,只要自己图书馆找本matlab初级教程,花个一周就能学会了。不难。语言不是问题,算法才是核心。matlab很好用,很重要。
再问: 刚才我运行了一下你给的程序哈,,输入今天的日期它输出 的是monday啊,今天是周二类。输入其他日期又有 错误,无法输出星期几。。好纠结啊,我也找不出哪儿错了,求大神详解。。
再答: 你要的[(DateToInt(year,mon,day) + 6)不是6天后的? 如果是要当天的 cxd = mod(myday+6,7); %%%%% 这行中+6去除即可得到今天的 改成:cxd = mod(myday,7) 例如: Input year:2003 Input month:10 Input day:1 the day is: 'Wednesday'
function [] = myhelp()
clear;
clc;
week = ['Monday ';'Tuesday ';'Wednesday';'Thursday ';'Friday ';'Saturday ';'Sunday '];
week = cellstr(week);
%printf('Input the date (eg 2013 10 21 , -1 ends the input):\n');
year = input('Input year:');
mon = input('Input month:');
day = input('Input day:');
myday = DateToInt(year,mon,day);
cxd = mod(myday+6,7);
disp('six days later is:')
disp(week(cxd))
function myday = DateToInt(year,mon,day)
days =[31,28,31,30,31,30,31,31,30,31,30,31;31,29,31,30,31,30,31,31,30,31,30,31];
myday = 0;
t = is_leap(year);
for ii = 1:year-1
myday = myday + is_leap(ii)*366+(1-is_leap(ii))*365;
for jj = 1:mon-1
myday = myday + days(t+1,jj);
end
end
myday = myday + day;
function isleap = is_leap(year)
isleap = (mod(year,4)==0 && mod(year,100)~=0) || (mod(year,400)==0) ;
实例:
Input year:2013
Input month:10
Input day:22
six days later is:
'Monday'
有问题可以追问
copyright (c) cxd1301
再问: 同学,这个matlab我学了没多久,学习 C 有一些时间了,matlab语言有什么特点啊,如果我想编一个程序的话,用C还有点眉目,可用Matlab就不懂了,,求大神赐教!!
再答: 会C的话会matlab就很快了,matlab用C内核,主体还是C++的东西,其语言其实是类C语言,只要自己图书馆找本matlab初级教程,花个一周就能学会了。不难。语言不是问题,算法才是核心。matlab很好用,很重要。
再问: 刚才我运行了一下你给的程序哈,,输入今天的日期它输出 的是monday啊,今天是周二类。输入其他日期又有 错误,无法输出星期几。。好纠结啊,我也找不出哪儿错了,求大神详解。。
再答: 你要的[(DateToInt(year,mon,day) + 6)不是6天后的? 如果是要当天的 cxd = mod(myday+6,7); %%%%% 这行中+6去除即可得到今天的 改成:cxd = mod(myday,7) 例如: Input year:2003 Input month:10 Input day:1 the day is: 'Wednesday'