Monday, September 5, 2011

Monday 9.6.11

#include
char line[100]; //input link from console
int value; //a value to double

int main()
{
printf("Enter a value: ");

fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &value);

printf("Twice %d is %d\n", value, value*2);
return(0);
}


#include
char line[50];
int radius = 0;
float pi = 3.14;
float fourThree = 4 / 3;

float volume = 0;

//find out the volume of a sphere given the radius
int main()
{
printf("Enter the radius: ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &radius);

// 4/3(pi)(r^3)
volume = radius*radius*radius*pi*fourThree;
printf("The volume is %f", volume);
return(0);
}


#include
int old_number;
int current_number;
int next_number;

int main()
{
//start things out
old_number = 1;
current_number = 1;

printf("1\n"); //print first number

while(current_number < 500)
{
printf("%d\n", current_number);
next_number = current_number + old_number;

old_number = current_number;
current_number = next_number;
}
return(0);

}


#include
char line[100];
int total;
int item;

int main()
{
total = 0;
while (1) {
printf("Enter # to add to \n");
printf(" or 0 to stop: ");

fgets(line, sizeof(line), stdin);
sscanf(line, "%d", &item);

if (item == 0)
{
break;
}

total += item;
printf("Total: %d\n", total);
}
printf("Final total %d\n", total);
return (0);
}

No comments: