#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);
}
请问程序的错误在那里!!!谢谢了!!在线等!!!

解决方案 »

  1.   

    至少没有:#include "stdio.h"
      

  2.   

    error C2296: '%' : illegal, left operand has type 'float'
    error C2297: '%' : illegal, right operand has type 'float'
      

  3.   

    你是不是想 c = a / b ;?
      

  4.   

    c=a%b也不对,%又不支持float型,如果是想做除法的话改为
    c=a/b
      

  5.   

    我认为错误在于数据类型使用不当
    把c=a%b
    改为c=(int)a%(int)b
    我没有测试,这样在理论上至少行
      

  6.   

    我总结一下结论吧!呵呵
    #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);
    }
      

  7.   

    哈哈
    您已经试了吗?
    对吗??/
    #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);
    }
    输出结果不一样唉,怎么办呢》???????????????????????
      

  8.   

    对于第一个程序由于使用"%f,%f",所以输入的时候一定要以","作为分隔符,而不能用空格,否则b就读不到数了(成为随机数),scanf()就是这个德性,没办法比如必须输入"13,7",而不能输入"13 7"
      

  9.   

    xfr_1982(独孤一笑) ( ) 信誉:100 你写的两个程序一模一样,输出结果也是一样的阿
      

  10.   

    回复人: limd(Limd) ( ) 信誉:100  2003-08-12 05:16:00  得分:0 
     
     
      上面的可以通过,在TC3.0下试了一下,可以了
      
     
    Top 
     
    不行呢!!?????
      

  11.   

    1、在vc++中要包含头文件
    #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);
    }
      

  12.   

    基本如楼上所说。正确代码如下:
    #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 ;
    }
      

  13.   

    #include "stdafx.h"
    #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是实数,而你对实数进行一个求余数的运算.这在数学里是不允许的求余数的运算面向的对象是整数!!
      

  14.   

    呵呵,xgp1226说的很好!
    这不是一个软件或者说程序问题,是一个数学问题!
    实数之间是不会有求模之说的!