Chapt 3
3.2
1) &average is the location or address
on the computer of the
variable average.
3) Address of variables:
#include <stdio.h>
/*Address of variables on the computer*/
main()
{
char *key, *choice;
int *num, *count;
long *ddate;
float *yield;
double *price;
key=&key;
choice=&choice;
num=#
count=&count;
ddate=&ddate;
yield=&yield;
price=&price;
printf("The address on the computer of
the char variable ""key"" is %c.\n",key);
printf("The address on the computer of
the char variable
""choice"" is %c.\n",choice);
printf("The address on the computer of
the int variable ""num"" is %d.\n",num);
printf("The address on the computer of
the int variable ""count"" is %d.\n",count);
printf("The address on the computer of
the long variable ""date"" is %f.\n",ddate);
printf("The address on the computer of
the float variable ""yield"" is %f.\n",yield);
printf("The address on the computer of
the double variable ""price"" is %f.\n",price);
}
3.3
1)use
scanf
a)scanf("%d",&firstnum);
b)scanf("%f",&grade);
c)scanf("%lf",&secnum);
d)scanf("%c",&keyval);
e)scanf("%d %d",&month,&years);
scanf("%f",&average);
f)scanf("%c",&ch);
scanf("%d
%d",&num1,&num2);
scanf("%lf",&grade1,&grade2);
g)scanf("%f %f
%f",&interest,&principal, &captial);
scanf("%lf
%lf",&price,&yield);
h)scanf("%c %c
%c",&ch,&letter1,&letter2);
scanf("%d
%d %d",&num1,&num2,&num3);
i)scanf("%f %f
%f",&temp1,&temp2,&temp3);
scanf("%lf
%lf",&volts1,&volts2);
2)declare
a)int day;
b)char fir_char;
c)float grade;
d)long price;
e)int num1,num2;
char ch1;
f)float firstnum, secnum;
int count;
g)char ch1,ch2;
int flag;
long average;
3)fit-it
a)scanf("%d",&num1);
b)scanf("%d %f %lf",&num1,&firstnum,
&price);
c)scanf("%d %f %lf",&num1, &secnum,
&yield);
d)scanf("%d %d%lf",&num1,&num2,
&yield);
e)scanf("%d %d",&num1,&num2);
f)scanf('%d",&num1);
4)
a) #include
<stdio.h>
main()
/*Circumference of a circle by Wendi Medley*/
{
float radius;
printf("Please enter the radius of a
circle, then hit ""Enter"":");
scanf("%f",&radius);
printf("The circumference is
%f",radius*6.2834);
}
4)
b)
Test run with 5 as the circumference. 5*6.2834 is 31.417 – It all checks
out.
6)Area
of a circle
a)
#include <stdio.h>
main()
/*Area of a
room by Wendi Medley*/
{
float length, width;
printf("Please enter length of the room, then hit
""Enter"":");
scanf("%f",&length);
printf("Please enter width of the room, then
hit ""Enter"":");
scanf("%f",&width);
printf("The area of the rectangle is
%.0f",length*width);
}
b)
L=1,w=12 a=12 everything checked out
7)miles
per gallon
a)
#include <stdio.h>
main()
/*Area of a
rectangle by Wendi Medley*/
{
float miles, gas;
printf("Please enter the miles driven, then
hit ""Enter"":");
scanf("%f",&miles);
printf("/nPlease enter gallons of gas
used,then hit ""Enter"":");
scanf("%f",&gas);
printf("Your car is getting %.2f miles per
gallon",miles/gas);
}
b)
milage=20 gallons=4, total mpg=5, it’s all good, except for that mph.
9)
a) average of 4
numbers:
#include <stdio.h>
main()
/*Area of a
rectangle by Wendi Medley*/
{
float num1,num2,num3,num4, total;
printf("Please enter a number, then hit
""Enter"":\t");
scanf("%f",&num1);
printf("Please enter another number, then hit
""Enter"":\t");
scanf("%f",&num2);
printf("Please enter a third number, then hit
""Enter"":\t");
scanf("%f",&num3);
printf("Please enter the last number, then
hit ""Enter"":\t");
scanf("%f",&num4);
printf("The average of all four numbers you
entered is:
%.2f.",(num1+num2+num3+num4)/4);
}
b)checked
out I entered all my numbers as a 2 and , yep, you guessed it, 2
was
my average.
c)using
the sum=sum+1 thingy
#include
<stdio.h>
main()
/*Area of a rectangle by Wendi Medley*/
{
float number, sum;
printf("Please enter a number, then hit
""Enter"":\t");
scanf("%f",&number);
sum=number;
printf("Please enter another number, then hit
""Enter"":\t");
scanf("%f",&number);
sum=sum+number;
printf("Please enter a third number, then hit
""Enter"":\t");
scanf("%f",&number);
sum=sum+number;
printf("Please enter the last number, then hit
""Enter"":\t");
scanf("%f",&number);
sum=sum+number;
printf("The sum is %f",sum);
}
Need
to ask for help an how to work out the average this way