#2995: 莫名奇妙溢位= =


b821213 (後繼無人)


#include <stdio.h>
#include <math.h>
#include <stdlib.h>


int main(){
  int i,temp=1;
  int n;
  float fors;
  int a,b;
 
       scanf("%d %d",&a,&b);
       for(i=0;i<b;i++)
        {temp=temp*a;}
       printf("%d\n",temp);
       
       scanf("%f",&fors);
       printf("%.3f\n",pow(fors,0.5));
       scanf("%d",&a);
       if(a<0){a*=-1;}
       printf("%d\n",a);

       scanf("%d %d",&a,&b);
       i=rand()%a+a;
       while(i>=b){i=rand()%a+a;}
       printf("%d\n",i);
       
 

 
 
 
   return 0;   
}

 

 

傳了n次都說我第二筆資料RE 說明是可能是溢位或者除0

可是參考過討論區很多人的答案 都發現我的float跟大家都一樣阿...怎會這樣...

#2996: Re:莫名奇妙溢位= =


awpkiller (討厭不跟範例輸入的測資(吼))


#include
#include
#include


int main(){
  int i,temp=1;
  int n;
  float fors;
  int a,b;
 
       scanf("%d %d",&a,&b);
       for(i=0;i
        {temp=temp*a;}
       printf("%d\n",temp);
       
       scanf("%f",&fors);
       printf("%.3f\n",pow(fors,0.5));
       scanf("%d",&a);
       if(a<0){a*=-1;}
       printf("%d\n",a);

       scanf("%d %d",&a,&b);
       i=rand()%a+a;
       while(i>=b){i=rand()%a+a;}
       printf("%d\n",i);
       
 

 
 
 
   return 0;   
}

 

 

傳了n次都說我第二筆資料RE 說明是可能是溢位或者除0

可是參考過討論區很多人的答案 都發現我的float跟大家都一樣阿...怎會這樣...

如果a=0的話,你 %0 會如何?
#3002: Re:莫名奇妙溢位= =


b821213 (後繼無人)


#include
#include
#include


int main(){
  int i,temp=1;
  int n;
  float fors;
  int a,b;
 
       scanf("%d %d",&a,&b);
       for(i=0;i
        {temp=temp*a;}
       printf("%d\n",temp);
       
       scanf("%f",&fors);
       printf("%.3f\n",pow(fors,0.5));
       scanf("%d",&a);
       if(a<0){a*=-1;}
       printf("%d\n",a);

       scanf("%d %d",&a,&b);
       i=rand()%a+a;
       while(i>=b){i=rand()%a+a;}
       printf("%d\n",i);
       
 

 
 
 
   return 0;   
}

 

 

傳了n次都說我第二筆資料RE 說明是可能是溢位或者除0

可是參考過討論區很多人的答案 都發現我的float跟大家都一樣阿...怎會這樣...

如果a=0的話,你 %0 會如何?



真的耶!我沒有注意到!太感謝你了~~~!

後來這題我選擇不用rand做了= =

不過...如果以後還有這種問題 可以怎麼解決呢?