All pastes #389698 Raw Edit

Untitled

public c v1 · immutable
·published 2007-03-10 22:05 UTC
rendered paste body
#include <stdio.h>/* Replacement resistance. */int ohm_calc(float ampere, float volt, float ohm){	float result = 0;	if((ampere == 0) && (volt == 0) && (ohm == 0))	{		printf("You have to give at least two values.\n");	}	if(ampere == 0)	{		result = volt / ohm;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", volt, ohm, result);	}	if(volt == 0)	{		result = ohm * ampere;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", result, ohm, ampere);	}	if(ohm == 0)	{		result = volt / ampere;		printf("Volt: %f\nOhm: %f\nAmpere: %f\n", volt, result, ampere);	}	return 0;}/* Main function */int main(){	int which;	float volt, ampere, ohm;	int i;	int size;	float rr[size];	float result = 0;	printf("What do you wanna calculate?\n0 = Ohm, Ampere or Voltage.\n1 = Replacement resistance.\n\n");	printf("Choose:_\b");	scanf("%d", &which);	switch(which)	{		case 0:			printf("Welcome. Give me the values of Ohm, Ampere and Voltage.\n");			printf("The one you set as 0 is the one that is going to be calculated.\n");			printf("Volt:_____\b\b\b\b\b");			scanf("%f", &volt);			printf("Ampere:_____\b\b\b\b\b");			scanf("%f", &ampere);			printf("Ohm:_____\b\b\b\b\b");			scanf("%f", &ohm);			ohm_calc(ampere, volt, ohm);			break;			case 1:				printf("Give me how many numbers you are going to use.\n");				printf("Size:__\b\b");				scanf("%d", &size);				for(i = 1; i <= size; i++)				{					printf("Give me number %d:", i);					scanf("%f", &rr[i]);					printf("You gave me %f\n", rr[i]);				}				for(i = 1; i <= size; i++)				{					result = result + (1 / rr[i]);				}				result = 1 / result;				printf("Result: %f\n", result);			break;	}	return 0;}