C++编程 问题 求知!

来源:百度知道 编辑:UC知道 时间:2024/05/18 19:47:51
高手请进,捣乱的请让让,谢谢!
问题如下:题1:接收一个字符,例如用“+”表示加法,用“-”表示减法。接收numa和num2两数。如果输入的字符为“+”,则将这两个数相加并显示相应结果。如果输入的字符为“-”,则将这两个数相减并显示相应的值。
题2:输入某年某月某日,判断这一天是这一年的第几天。
(本人是初学者,请不要用太复杂的,if/switch结构就行了。。。答题时请附详细解释,如果通过本人感激涕淋!!!)

第二题的C答案自己看看改改吧
#include<stdio.h>
void main()
{
int a,b,c,d;
printf("Please input year month day:");
scanf("%d%d%d",&a,&b,&c);

if(b>=12)
printf("Error\n");
else if((b==1||3||5||7||8||10||12)&&(c>=31))
printf("Error\n");
else if((b==4||6||9||11)&&(c>=30))
printf("Error\n");
else if( (a%4!=0)&&(b==2)&&(c>=28))
printf("Error\n");
else if( (a%4==0)&&(b==2)&&(c>=29))
printf("Error\n");
else
if(b==1)
printf("It is the %d day of this year\n",c);
else if(b==2)
printf("It is the %d day of this year\n",31+c);
else
{
if(a%4!=0)
{
if(b<=7)
if((b-1)%2==0)
d=31*(b-1)/2+30*(b-3)/2+28+c;
else d=31*b/2+28+30*(b-4)/2+c;