View Code of Problem 96

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int n;
	double sum;
	char s[100];
	while(scanf("%d%s",&n,&s)!=EOF){
		if(n==0){
			break;
		}
		if(strcmp(s,"B")==0){
			sum=0;
		}
		else if(strcmp(s,"KB")==0){
			sum=1024*n-1000*n;
		}
		else if(strcmp(s,"MB")==0){
			sum=(pow(1024,2)-pow(1000,2))*n;
		}
		else if(strcmp(s,"GB")==0){
			sum=(pow(1024,3)-pow(1000,3))*n;
		}
		else if(strcmp(s,"TB")==0){
			sum=(pow(1024,4)-pow(1000,4))*n;
		}
		printf("%.0lf\n",sum);
	}
}

Double click to view unformatted code.


Back to problem 96