Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help! Writing a C prgogram for following situation: (Illumination) Here is the c

ID: 657177 • Letter: H

Question

Help! Writing a C prgogram for following situation: (Illumination)

Here is the code, I have so far ( But it's not the correct program):

#include
#include

#include // include the math.h header

int main()
{

float c,h,d,i, l;

printf("power of lamps (in watt)? ");
scanf("%f",&c);
printf("height of lamp (in meter)? ");
scanf("%f",&h);
printf("distance apart (in meter)? ");
scanf("%f",&d);
printf("interval (in meter)? ");
scanf("%f",&i);

printf(" ");//print a line

printf("power: %.2f watts ",c);
printf("heigh: %.2f meters ",h);
printf("distance apart: %.2f meters ",d);
printf("interval: %.2f meters ",i);

d *= 3;

printf("d = %f i = %f ",d,i);

printf(" d L ");
printf("----- ------ ");

do{
float dd, x,y,z,w;
dd = i-d;
x=powf(dd,2);
printf("x: %2f ",x);
y=powf(h,2);
//printf("y: %2f ",y);
z=x+y;
//printf("z: %2f ",z);
w=powf(z,1.5);
//printf("w: %2f ",w);

l=(c*h)/w;
printf("%.2f %.5f ",i,l);

i*=2;
}while(i<=d);

return 0;

}

Try to enter these value to test(the correct program):

Explanation / Answer

#include <16f877a.h>

#device ICD=TRUE

#fuses HS,NOLVP,NOWDT,PUT

#use delay (clock=20000000)

  

#define LDR PIN_B4

#define LED1 PIN_B2

#define LED2 PIN_B0

#define LED3 PIN_D6

#define LED4 PIN_D4

#define LED5 PIN_D2

#define LED6 PIN_D0

  

void light_one_led(int led)      // define a function to be called from main

{

Output_low(LED1);    // turn OFF all LEDs

Output_low(LED2);

Output_low(LED3);

Output_low(LED4);

Output_low(LED5);

Output_low(LED6);

  

Switch(led)            // use Switch/Case statements to select LED

{

  Case 0 : output_c(LED1, (reading * 6)); break; //output_c?

  Case 1 : output_high(LED1);

           output_c(LED2, (reading - 42 * 6)); break;

  Case 2 : output_high(LED1);

           output_high(LED2);

           output_c(LED3, (reading - 84 * 6)); break;

  Case 3 : output_high(LED1);

           output_high(LED2);

           output_high(LED3);

           output_c(LED4, (reading - 126 * 6)); break;

  Case 4 : output_high(LED1);

           output_high(LED2);

           output_high(LED3);

           output_high(LED4);

           output_c(LED5, (reading - 168 * 6)); break;

  Case 5 : output_high(LED1);

           output_high(LED2);

           output_high(LED3);

           output_high(LED4);

           output_high(LED5);

           output_c(LED6, (reading - 210 * 6)); break;

}

}

  

void main( )

{

int reading;         

Setup_adc_ports (RA0_Analog);    // B4 Pin?

Setup_adc (ADC_CLOCK_INTERNAL); // Setup ADC

Set_adc_channel ( 0 );            // B4 Pin?

  

while(TRUE)

{

reading = read_adc( );

  if (reading >=0)&&(reading <42)

    light_one_led(0);      // LED 1 dimming

  else if (reading >=42)&&(reading <84)

    light_one_led(1);      // LED 1 on, LED2 dimming

  else if (reading >=84)&&(reading <126)

    light_one_led(2);      // LEDs 1 and 2 on, LED3 dimming

  else if (reading >=126)&&(reading <168)

    light_one_led(3);      // LEDs 1 - 3 on, LED4 dimming

  else if (reading >=168)&&(reading <210)

    light_one_led(4);      // LEDs 1 - 4 on, LED5 dimming

  else

    light_one_led(5);      // LEDs 1 - 5 on, LED6 dimming

  }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote