उपयोगकर्ता द्वारा खपत की गई यूनिट्स के आधार पर बिजली बिल जनरेट होता है। यदि खपत की गई यूनिट्स की संख्या अधिक है, तो यूनिट चार्ज की दर भी बढ़ जाएगी।
यदि उपयोगकर्ता द्वारा न्यूनतम यूनिट्स खपत की जाती हैं तो लागू लॉजिक:
if (units < 50){
amt = units * 3.50;
unitcharg = 25;
}
यदि यूनिट्स 50 से 100 के बीच हैं तो लागू लॉजिक:
else if (units <= 100){
amt = 130 + ((units - 50) * 4.25);
unitcharg = 35;
}
यदि यूनिट्स 100 से 200 के बीच हैं तो लागू लॉजिक:
else if (units <= 200){
amt = 130 + 162.50 + ((units - 100) * 5.26);
unitcharg = 45;
}
यदि यूनिट्स की संख्या 200 से अधिक है तो लागू लॉजिक:
amt = 130 + 162.50 + 526 + ((units - 200) * 7.75); unitcharg = 55;
इसलिए, अंतिम राशि निम्न लॉजिक से जनरेट होगी:
total = amt + unitcharg;
उदाहरण
बिजली बिल जनरेट करने के लिए C प्रोग्राम निम्नलिखित है:
#include <stdio.h>
int main(){
int units;
float amt, unitcharg, total;
printf(" Enter no of units consumed : ");
scanf("%d", &units);
if (units < 50){
amt = units * 3.50;
unitcharg = 25;
} else if (units <= 100){
amt = 130 + ((units - 50) * 4.25);
unitcharg = 35;
} else if (units <= 200){
amt = 130 + 162.50 + ((units - 100) * 5.26);
unitcharg = 45;
} else {
amt = 130 + 162.50 + 526 + ((units - 200) * 7.75);
unitcharg = 55;
}
total = amt + unitcharg;
printf("electricity bill = %.2f", total);
return 0;
}
आउटपुट
जब उपरोक्त प्रोग्राम चलाया जाता है, तो यह निम्नलिखित परिणाम देता है:
Enter no of units consumed: 280 electricity bill = 1493.50