编写一个程序,在C中打印两个输入整数的和,乘积和商

时间:2013-01-24 07:34:48

标签: c compiler-errors

我是该语言的新手,所有这些溢出问题和整数类型让我感到紧张。这就是我所拥有的,但是当我运行它时,我得到了,

-bash: syntax error near unexpected token `newline'

代码:

#include <stdio.h>
int main(void)
{
   int one, two, s, q, m;
   s = one+two
   q = one/two
   m = one*two
   printf("Enter first positive integer: ");
   scanf("%d", &one);
   printf("Enter second positive integer: ");
   scanf("%d", &two);
   printf("The addition of %d and %d is %d", one, two, s);
   printf("The integer division of %d divided by %d is %d", one, two, q);
   printf("the multiplication of %d and %d is %d", &one, &two, m);
   return 0;
}

谢谢

4 个答案:

答案 0 :(得分:1)

您应该在获得输入后执行计算。

printf("Enter first positive integer: ");
scanf("%d", &one);
printf("Enter second positive integer: ");
scanf("%d", &two);

s = one+two;
q = one/two;
m = one*two;

答案 1 :(得分:0)

试试这个:

#include <stdio.h>
int main(void)
{
int one, two;
printf("Enter first positive integer: ");
scanf("%d", &one);
printf("Enter second positive integer: ");
scanf("%d", &two);
printf("The addition of %d and %d is %d", one, two, (one+two));
printf("The integer division of %d divided by %d is %d", one, two, (one/two));
printf("the multiplication of %d and %d is %d", &one, &two, (one*two));
return 0;
}

答案 2 :(得分:0)

之后你缺少分号
   s = one+two
   q = one/two
   m = one*two

另外,您应该在阅读输入后执行计算,但这是一个不同的问题。

答案 3 :(得分:0)

这些行会产生问题:

s = one+two
q = one/two
m = one*two

您错过了;(分号)

将其更改为:

s = one+two;
q = one/two;
m = one*two;

在执行操作之前,还要先阅读用户的输入。