Data_Structure/作業/unit5/DS5_not_Recursion.cpp
2025-01-20 21:30:53 +08:00

38 lines
556 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int num ,i=0 , j=1 ,temp;
printf("*** 最小包裝面積之郵寄包過程式 ***\n\n輸入糖磚數 ==> ");
scanf("%d",&num);
temp = num ;
while(1){
if(pow(i,2)<=temp) i++;
else break;
}
i--;
printf("\n包裝方式為放若干排\n\n");
while(1){
if(temp>=i){
printf("第%d排%d個\n",j,i);
temp -= i;
j++;
}else if(temp!=0){
printf("第%d排%d個\n",j,temp);
j++;
break;
}else{
break;
}
}
j--;
printf("\n最小包裝紙面積 = %d\n",(j+i+num)*2*100);
return 0;
}