求C++大神帮忙回答几个小问题!关系平时作业成绩跪谢啊! 15
马上到学期末了TT我和舍友就这一次作业没交,因为我们C++平时分很重,我们又不是计算机专业的,所以感觉略吃力,求好心的C++大神帮帮两个无助的小女森吧!好人期末全过!--...
马上到学期末了T T我和舍友就这一次作业没交,因为我们C++平时分很重,我们又不是计算机专业的,所以感觉略吃力,求好心的C++大神帮帮两个无助的小女森吧!好人期末全过!
------------------------------分割线,以下是题目-----------------------------------
1. Write a function to get the sum of 1!+2!+3!+…8!
2. Write a C++ program that will print the day numbers of a given-year and month.
example: enter the year and month: 2013 5
the number of days in 2013.5 is 31.
3. read the programs and give the results.
1)#include<iostream>
using namespace std;
#include <string>
void main( )
{ char a[]="welcome",b[]="well";
strcpy(a,b);
cout<<a<<endl;
}
2)#include<iostream>
using namespace std;
void main( )
{ int a[10],i,sum0=0,sum1=0;
cout<<"please input 10 number:"<<endl;
for(i=0;i<10;i++)
cin>>a[i];
for(i=0;i<10;i++)
if(a[i]>=0) sum0+=a[i];
else sum1+=a[i];
cout<<"the sum of positive inputs is:"<<sum0
<<"the sum of negative inputs is:"<<sum1
<<endl;
}
3)#include<iostream>
using namespace std;
void main( )
{ int a[5][5],i,j,n=1,sum=0;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
a[i][j]=n++;
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
cout<<a[i][j]<<'\t';
cout<<'\n';
}
}
4. Find errors in the programs and modify them.
#include <iostream>
void main()
{ char x[]="abcdefghij";
cout<<x<<endl;
x="zyxwv";
cout<<x<<endl;
} 展开
------------------------------分割线,以下是题目-----------------------------------
1. Write a function to get the sum of 1!+2!+3!+…8!
2. Write a C++ program that will print the day numbers of a given-year and month.
example: enter the year and month: 2013 5
the number of days in 2013.5 is 31.
3. read the programs and give the results.
1)#include<iostream>
using namespace std;
#include <string>
void main( )
{ char a[]="welcome",b[]="well";
strcpy(a,b);
cout<<a<<endl;
}
2)#include<iostream>
using namespace std;
void main( )
{ int a[10],i,sum0=0,sum1=0;
cout<<"please input 10 number:"<<endl;
for(i=0;i<10;i++)
cin>>a[i];
for(i=0;i<10;i++)
if(a[i]>=0) sum0+=a[i];
else sum1+=a[i];
cout<<"the sum of positive inputs is:"<<sum0
<<"the sum of negative inputs is:"<<sum1
<<endl;
}
3)#include<iostream>
using namespace std;
void main( )
{ int a[5][5],i,j,n=1,sum=0;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
a[i][j]=n++;
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
cout<<a[i][j]<<'\t';
cout<<'\n';
}
}
4. Find errors in the programs and modify them.
#include <iostream>
void main()
{ char x[]="abcdefghij";
cout<<x<<endl;
x="zyxwv";
cout<<x<<endl;
} 展开
2个回答
展开全部
第一个
int func()
{
int tmpsum = 1;
int sum = 0;
for(int i = 1;i<=8;i++)
{
for(int j=i;j>0;j--)
{
tmpsum = tmpsum * j;
}
sum += tmpsum;
tmpsum = 1;
}
return sum;
}
第二题:
#include <iostream>
using namespace std;
void func1(int year, int month) //闰年
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout << "the number of days in "<<year <<"."<<month \
<< " is 31." << endl;
break;
case 4 :
case 6 :
case 9 :
case 11:
cout << "the number of days in "<<year <<"."<<month \
<< " is 30." << endl;
break;
case 2 :
cout << "the number of days in "<<year <<"."<<month \
<< " is 29." << endl;
break;
default :
cout << "input error" << endl;
break;
}
}
void func2(int year, int month)
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout << "the number of days in "<<year <<"."<<month \
<< " is 31." << endl;
break;
case 4 :
case 6 :
case 9 :
case 11:
cout << "the number of days in "<<year <<"."<<month \
<< " is 30." << endl;
break;
case 2 :
cout << "the number of days in "<<year <<"."<<month \
<< " is 28." << endl;
break;
default :
cout << "input error" << endl;
break;
}
}
int main()
{
int year = 0;
int month = 0;
cout << "enter the year and month: ";
cin >> year >> month;
if(year % 100 == 0)
{
if(year % 400 == 0)
{
func1(year,month);
}
else
{
func2(year,month);
}
}
else
{
if(year % 4 == 0)
{
func1(year,month);
}
else
{
func2(year,month);
}
}
return 0;
}
第三题:
well
第四题
#include <iostream>
using namespace std; //缺少命名空间引用
void main()
{
char x[]="abcdefghij";
cout<<x<<endl;
x="zyxwv"; //无法将char[6]赋值个char[11]
用strcpy(x,"zyxwv"); 加头文件 <string.h>
cout<<x<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.int sum()
{
long x, j, sum;
j=1, sum = 0;
for(x=1; x <= 8; x++)
{
j*=x;
sum += j;
}
return sum;
}
2.
#include<iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string year;
int month;
stringstream ss;
cout<<"enter the year and month:";
cin>>year>>month;
ss.str("");
ss << month;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout<<" the number of days in "+year+"."+ss.str() +" is 31.";
break;
case 4:
case 6:
case 9:
case 11:
cout<<" the number of days in "+year+"."+ss.str() +" is 30.";
break;
default:
cout<<" the number of days in "+year+"."+ss.str() +" is 28.";
}
return 0;
}
3.1 well
3.2 please input 10 number:
3.3
6
11 12
16 17 18
21 22 23 24
4.
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char x[]="abcdefghij";
cout<<x<<endl;
//x="zyxwv";
strcpy(x,"ayxwv");
cout<<x<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询