Question

in c language 9. Given the following variable definitions: int A, B, C; double D; Is...

in c language

9. Given the following variable definitions:

int A, B, C;

double D;

Is there a difference between the following lines code?

If so explain why.

D = A/4 + B/2+ C;

D = A*0.25 + B*0.5 + C;

D = A/4.0 + B/2.0+ C;

12. Given the integer variable, boiling; boiling = true, only if the real-valued temperature is above 212. Define the two variables and write the IF statement.

13. The variables F and C hold the real-valued Fahrenheit and Celsius temperature. ? = 9 5 ? + 32. Define the variables and program the expression for C.

14. The variables dollars, quarters, dimes, nickels, and pennies are used to hold the integer count of each currency denomination. The variable total represents the total amount of money, e.g. if dollars=2, quarters=3, dimes=4, nickels=5, and pennies=6 then total = 2+0.75+0.4+0.25+0.06. Show the definition for all the variables and the expression for total.

15. Returns TRUE or FALSE if the input integer to the function is positive (TRUE means the number is positive).

16. A multidimensional array is used to store the one integer grade for 30 students in 100 courses.

a. Show the variable definition of array.

b. Use scanf to read from the user a grade for the last student, in the first course.

17. The variable array contains 100 integer values.

a. Show the variable definition

b. Use printf to print all values in the array consecutively and separated by commas and put a full stop at the end.

18. The variables x1, x2, and y1, y2 represent real values of a line equation. The variables m and b represent the slope and y-intercept respectively. Define all variable and program the expressions for m and b.

19. There are 3 integer numbers: num1, num2, num3. The middle equals to the number that has one numbers greater than it and one number smaller than it. Use If statements to find the middle number.

20. Given an array of 12 integers. Use the following function to determine the max value in the array.

int max (int a, int b)

{

if (a>b) return a;

else

return b;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answers are given Below : (THUMBS UP PLEASE IF IT HELPS)

Answer 9)

Suppose A = B = C = 1

Yes there is a difference in the 3 statements, when A/4 it gives us 0, but when A*0.25 it gives 0.25 and when A/4.0 due to precision we get 0.25.

#include <stdio.h>

int main()
{
int A = 1, B = 1, C = 1;
double D;
D = A/4 + B/2 + C;
printf("%f\n",D);
D = A*0.25 + B*0.5 + C;
printf("%f\n",D);
D = A/4.0 + B/2.0 + C;
printf("%f\n",D);
  
}

OUTPUT

Answer 12)

#include <stdio.h>
#include <stdbool.h>
int main()
{
bool boil = false;
double boiling;
printf("Enter the temperature : ");
scanf("%lf",&boiling);
if(boiling>212)
boil = true;
if(boil)
printf("The Liquid is boiling ");
else
printf("The Liquid is not boiling");
}
OUTPUT

Answer 13

#include <stdio.h>
#include <stdbool.h>
int main()
{
double C=0.0,F=90.0;
// for Fahrenheit to celcius
C = (F-35)*5;
C= C / 9;
printf("Value of %.2f F is calculated by ",F);
printf("(F-35)*(5/9)");
printf(" : %.2f C",C);
}

OUTPUT

Answer 14)

#include <stdio.h>
#include <stdbool.h>
int main()
{
double dollar,quarter,dimes,nickels,pennies,total;
printf("EnterNumber of dollar,quarter,dimes,nickels,pennies\n");
scanf("%lf %lf %lf %lf %lf",&dollar,&quarter,&dimes,&nickels,&pennies);
dollar = 1.00*dollar;
quarter = 0.25*quarter;
dimes = 0.10*dimes;
nickels = 0.05*nickels;
pennies = 0.01*pennies;
total = dollar+dimes+quarter+nickels+pennies;
printf("Total amount is %.2f",total);
}
OUTPUT

Answer 15)

#include <stdio.h>
#include <stdbool.h>
bool trueFalse(int a)
{
if(a>=0)
{
return true;
}
else
{
return false;
}
}
int main()
{
int num1 = 2, num2=-2;
if(trueFalse(num1))
printf("%d : TRUE\n",num1);
if(!trueFalse(num2))
printf("%d : FALSE",num2 );
  
}
OUTPUT

Answer 16)

#include <stdio.h>
#include <stdbool.h>

int main()
{

// defination
int grade[30][100];

//inserting value
printf("Enter values of 30th student First course : ");
scanf("%d",&grade[29][0]);
  
printf("You Entered Value %d",grade[29][0]);
}

OUTPUT

Answer 17)

#include <stdio.h>
#include <stdlib.h>

int main()
{
int array[100],i;
for(i=0;i<100;i++)
{
array[i] = rand()%10 + 1;
}
for(i=0;i<100;i++)
{
if(i!=99)
{
printf("%d,",array[i]);
}
else
{
printf("%d.",array[i]);
}
}   
}
OUTPUT

Answer 18)

#include <stdio.h>
#include <stdlib.h>

int main()
{
float x1, x2, y1, y2, c,yintecept;
double m;
x1=2; x2=3; y1=2; y2=4; c=0;
m=(y2-y1)/(x2-x1);
c=y2-(m*x2);
printf("slope : %.0f \n",m);
yintecept = 0*m + c;
printf("Y-intercept : (%0.0f,0)",yintecept);
  
}

OUTPUT

Answer 19)

//Program to find middle number among 3 numbers:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int A, B, C,largest,mid,small;
  
printf("Enter three numbers: ");
scanf("%d %d %d", &A, &B, &C);
  
if (A >= B) {
if (A >= C)
{
largest = A;
if(B>=C)
mid = B;
else
mid = C;
}
else
{
largest = C;
if(A>=B)
mid = A;
else
mid = B;
}
}
else {
if (B >= C)
{
largest = B;
if(A>=C)
mid = A;
else
mid = C;
}
else
{
largest = C;
if(B>=A)
mid = B;
else
mid = A;
}
}
  
printf ("Middle Number is %d",mid);
return 0;
}
OUTPUT:

Answer 20)

#include <stdio.h>
int max(int a, int b)
{
if(a>b)
return a;
else
return b;
}

int main()
{ int i,m,n;
int arr[12]={10, 5, 8, 9, 11, 15, 16, 58, 14, 33, 22, 17};
m = arr[0];
for(i=0;i<12;i++)
{
n = max(arr[i],arr[i+1]);
if(m<n)
m =n;
}
printf("Larget number is : %d",m);
return 0;
}
OUTPUT

Add a comment
Know the answer?
Add Answer to:
in c language 9. Given the following variable definitions: int A, B, C; double D; Is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT