View Code of Problem 96

#include<stdio.h>
#include<math.h>
main() {
	int num;
	char type[3];
	while (scanf("%d",&num)!=EOF&&num!=0)
	{
		double count=0;
		scanf("%s", type);
		if (strcmp(type, "B") == 0)
		{
		
			printf("0\n");
		}
		else if (strcmp(type, "KB") == 0)
		{
			count = num * (pow(1024.0, 1) - pow(1000.0, 1));
			printf("%.0lf\n", count);
		}
		else if (strcmp(type,"MB")==0)
		{
			count = num * (pow(1024.0, 2) - pow(1000.0, 2));   
			printf("%.0lf\n",count);                   //%lf是double的输出格式 .0是保留0位小数
		}
		else if (strcmp(type, "GB") == 0)
		{
			count = num * (pow(1024.0, 3) - pow(1000.0, 3));
			printf("%.0lf\n", count);
		}
		else if (strcmp(type, "TB") == 0)
		{
			count = num * (pow(1024.0, 4) - pow(1000.0, 4));
			printf("%.0lf\n", count);
		}
	}
}
	

Double click to view unformatted code.


Back to problem 96