有关C语言的程序问题,不会做。。。求大神帮忙!
Task2Writeafunctiontodetermineifthegivenyearisaleapyear.Ifitis,return1,otherwiseretur...
Task 2 Write a function to determine if the given year is a leap year. If it is, return 1, otherwise return 0.
Task 3 Write and test a function to print Floyd's triangle of n rows.
Number of rows of Floyd's triangle to print is entered by the user.
If n is 4, then the output should be as follows :
1
2 3
4 5 6
7 8 9 10
Task 4 Write and test a recursive C-function that calculates the series: 1+2+3+4+5+.........+N.
Task 5. Write and test the following recursive function that returns the nth square number:
long sqrFun(int n)
the square numbers are 0, 1, 4, 9, 16, 25, 36, ...
Note that s(n)=s(n-1)+2n-1 for n>1.
Task 6 Write and test a function which accepts any month-year and displays the calendar of the month.
For example, if the input is: 06-2014
then the output should be something like this:
JUNE, 2014
SUN MON TUE WED THU FRI SAT
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 展开
Task 3 Write and test a function to print Floyd's triangle of n rows.
Number of rows of Floyd's triangle to print is entered by the user.
If n is 4, then the output should be as follows :
1
2 3
4 5 6
7 8 9 10
Task 4 Write and test a recursive C-function that calculates the series: 1+2+3+4+5+.........+N.
Task 5. Write and test the following recursive function that returns the nth square number:
long sqrFun(int n)
the square numbers are 0, 1, 4, 9, 16, 25, 36, ...
Note that s(n)=s(n-1)+2n-1 for n>1.
Task 6 Write and test a function which accepts any month-year and displays the calendar of the month.
For example, if the input is: 06-2014
then the output should be something like this:
JUNE, 2014
SUN MON TUE WED THU FRI SAT
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 展开
1个回答
展开全部
// 闰年
int is_leap_year(unsigned int year)
{
int ret = 0;
if( ! (year%400))
{
ret = 1;
}
else if(year%100)
{
ret = !(year%4);
}
return ret;
}
void Floyd_triangle(unsigned int row)
{
int i,j;
unsigned int num = 1;
for( i = 0; i < row; i++)
{
for( j = i + 1; j; j--)
{
printf("%-5d",num++);
}
printf("\n");
}
}
//递归计算1+2+3+4+5+.........+N.
unsigned recursive_calc (unsigned int num)
{
if( num == 1)
return num;
return num+recursive_calc(num-1);
}
//returns the nth square number
long sqrFun(int n)
{
if( n == 0 )
{
return 0;
}
return sqrFun(n-1)+2*n-1;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询