#include "math.h"
main()
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
c=a%b;
printf("%f",c);
}
请问程序的错误在那里!!!谢谢了!!在线等!!!
main()
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
c=a%b;
printf("%f",c);
}
请问程序的错误在那里!!!谢谢了!!在线等!!!
解决方案 »
- DrawText最后一个文字显示不完整
- 关于tabctrl标签页位置的问题,谢谢回答
- 请问谁有IWMPNetwork的封装类文件? 如果告诉我如何从CWMPPlayer4获取这个接口也行
- 关于树形控件问题
- 请教高手:关于Navigate2在CHtmlView中显示的问题
- 如何用VC编程对sql server进行过数据库管理的?
- vc++6.0 的资源问题
- 我想知道有没有这样一种对话框?
- 有谁知道小榕朔雪软件的那个效果怎样实现的啊?解决的50分~
- Install 6.3使用6.2的语言包,汉化不彻底,怎么办
- MFC 已打开几个对话框,每个对话框标题不同,如何判断哪一个已经打开、哪一个未打开。
- 该如何写这条SQL语句?
error C2297: '%' : illegal, right operand has type 'float'
c=a/b
把c=a%b
改为c=(int)a%(int)b
我没有测试,这样在理论上至少行
#include <stdio.h>
#include <math.h>
void main()
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
if((int)b==0)//分母不能为0
return;
c=(float)((int)a%(int)b);
printf("%f",c);
}
您已经试了吗?
对吗??/
#include <stdio.h>
#include <math.h>
void main()
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
if((int)b==0)//分母不能为0
return;
c=(float)((int)a%(int)b);
printf("%f",c);
}
与
#include <stdio.h>
#include <math.h>
void main()
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f%f",&a,&b);
if((int)b==0)//分母不能为0
return;
c=(float)((int)a%(int)b);
printf("%f",c);
}
输出结果不一样唉,怎么办呢》???????????????????????
上面的可以通过,在TC3.0下试了一下,可以了
Top
不行呢!!?????
#include "stdio.h"
2、求余操作%左右操作数都必须为整型变量
完整的代码如下,编译通过。
#include "math.h"
#include "stdio.h"
main()
{
//float a;
int a;
// float b;
int b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%d,%d",&a,&b);
c=a%b;
printf("%f",c);
}
#include <stdio.h>
#include <math.h>void main()
{
int a;
int b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%d,%d",&a,&b);
c=float(a%b);
printf("%f",c);
return ;
}
#include"stdio.h"
#include "math.h"
int main(int argc, char* argv[])
{
float a;
float b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
c=a%b;
printf("%f",c);
return 0;
}
如果改上面这样,错误为为样:H:\My C++\csdn2\csdn2.cpp(14) : error C2296: '%' : illegal, left operand has type 'float'
#include "stdafx.h"
#include"stdio.h"
#include "math.h"
int main(int argc, char* argv[])
{
int a,b;
float c;
printf("\nshu ru 2 ge shu :");
scanf("%f,%f",&a,&b);
c=a%b;
printf("%f",c);
return 0;
}
第二个程序是能够通过的.
错误在于你定义了a,b是实数,而你对实数进行一个求余数的运算.这在数学里是不允许的求余数的运算面向的对象是整数!!
这不是一个软件或者说程序问题,是一个数学问题!
实数之间是不会有求模之说的!