唉!这些题都还蛮简单的啊,看你需要帮助,还是江湖救济下哈,自己好好体会下啊,代码可直接运行的,祝你好运
第一题
#include
int main()
{
int n,sum;
while(scanf("%d",&n))
{
sum = 0;
if((n>=0)&&(n<=10))
{
sum = n * 60;
}
else if((n>=11)&&(n<=39))
{
sum = n * 50;
}
else
{
sum = n *45;
}
printf("%d\n",sum);
}
return 0;
}
第二题
#include
int main()
{
int n;
char s[8][10]={"date", //该字符串保留
"monday",
"tuesday",
"wednesday",
"thirsday",
"friday",
"saturday",
"sunday"
};
while(scanf("%d",&n))
{
if((n>7)||(n<=0))
{
printf("error data\n");
}
else
{
printf("%s\n",s[n]);
}
}
return 0;
}
第三题
#include
int main()
{
int n,i;
float sum;
while(scanf("%d",&n))
{
sum = 0;
for(i = 1;i<=n;i++)
{
sum += 1.0/(2*i-1);
}
printf("%0.2f\n",sum);
}
return 0;
}
第四题
#include
#include
int main()
{
int a,b,sum;
while(scanf("%d%d",&a,&b))
{
sum = 0;
if(a%b==0)
{
sum = a*a + b*b;
}
else if(b%a==0)
{
sum = a*a*a +b*b*b;
}
else
{
sum = abs(a-b);
}
printf("%d\n",sum);
}
return 0;
}
第五题
#include
#include
int main()
{
float a,b,c,ds,x1,x2;
printf("enter a,b,c:");
while(scanf("%f%f%f",&a,&b,&c))
{
if(a==0) //一元方程
{
if(b==0)
{
printf("方程无解\n"); //两边是常数,无解
}
else
{
printf("%0.2f\n",-c/b);//一次方程一个解
}
}
else
{
ds = b*b-4*a*c; //二次方程
if(ds<0)
{
printf("error!!!!!\n"); //小于0无实根
}
else if(ds==0) //等于0,两相等实根
{
x1 = -b/(float)(2*a);
printf("x1 = x2 = %f\n",x1);
}
else //大于0,两不等实根
{
x1=(-b+sqrt(ds))/(float)(2*a);
x2=(-b-sqrt(ds))/(float)(2*a);
printf("x1 = %f,x2 = %f\n",x1,x2);
}
}
}
return 0;
}
这样简单的问题也拿出来,你没有学过C语言吧
1.
#include
using namespace std;
int main()
{
int amount;
cout << "输入您要买的商品数量:\n";
cin >> amount;
cout << "总价为:";
if(amount<=0)
cout << "0";
else if(amount>=0&&amount<=10)
cout << 60*amount;
else if(amount>=11&&amount<=39)
cout << 50*amount;
else
cout << 40*amount;
cout<< "元";
system("pause");
}
2.
#include
using namespace std;
int main()
{
cout << "输入一个1-7之间的数字:\n";
int a;
cin >> a;
switch(a)
{ case 1: cout << "monday";break;
case 2: cout << "tuesday";break;
case 3: cout << "wednesday";break;
case 4: cout << "thursday";break;
case 5: cout << "friday"; break;
case 6: cout << "saturday";break;
case 7: cout << "sunday";break;
default: cout << "error data";}
system("pause");
}
3.
#include
using namespace std;
int main()
{
int n;
int answer=0;
cout << "输入一个数字N\n";
if(n<=0)
{ cout<<"输入有误"; main();}
for(int i=0;i
answer = answer + (1/(2i-1));
}
cout << "答案是:" << answer";
system("pause");
}
4.
#include
using namespace std;
int main()
{
int a,b;
cin >> a;
cin >> b;
if(a%b==0)
cout << a*a + b*b;
else if(b%a==0)
cout << a^3 + b^3;
else
{ if(a>=b)
cout << a-b;
else
cout << b-a;}
system("pause");
}
5.
#include
using namespace std;
int main()
{
int a,b,c;
cin>>a;
cin>>b;
cin>>c;
if(a==0)
cout<< -(c/b);
else
{
if((b^2-4*a*c)>0)
cout << (-b +(b^2-4a*c)^(1/2))/2 << " 和 " << (-b-(b^2-4a*c)^(1/2))/2;
else
cout << -(b/2a);
}
system("pause");
}