View Code of Problem 96

#include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
	double a,c;
	char b[5];
	double s[100];
	int i=0;
	while(scanf("%d",&a)!=EOF){
		gets(b);
		if(a==0){
			break;
		}
		if(strcmp(b,"KB")==0){
			c=a*(1024-1000);
			s[i++]=c;
		}
		if(strcmp(b,"MB")==0){
			c=a*(pow(1024,2)-pow(1000,2));
			s[i++]=c;
		}
		if(strcmp(b,"GB")==0){
			c=a*(pow(1024,3)-pow(1000,3));
			s[i++]=c;
		}
		if(strcmp(b,"TB")==0){
			c=a*(pow(1024,4)-pow(1000,4));
			s[i++]=c;
		}
	}
	int j;
	for(j=0;j<i;j++){
		printf("%d\n",s[j]);
	}

	printf("\n");
	return 0;
}

Double click to view unformatted code.


Back to problem 96