Skip to main content

Posts

Showing posts from March 20, 2013

Program will accept Year,Month and Date from the user and will display the day of the month.

#include<stdio.h> #include<conio.h> #include<math.h> int isdatevalid( int month, int day, int year) { if (day <= 0) return 0 ; switch ( month ) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (day > 31) return 0 ; else return 1 ; case 4: case 6: case 9: case 11: if (day > 30) return 0 ; else return 1 ; case 2: if ( day > 29 ) return 0 ; if ( day < 29 ) return 1 ; else return 0 ; } return 0 ; } //------------------------------------------------ int fm( int date, int month, int year) { int fmonth,leap; //leap function 1 for leap & 0 for non-leap if ((year%100==0) && (year%400!=0)) leap=0; else if (year%4==0) leap=1; else leap=0; fmonth=3+(2-leap)*((month+2)/(2*month))+(5*month+month/9)/2; //f(m) formula fmonth = fmonth % 7; //bring it in range of 0 to 6 return fmonth; } //---------------------------------------------- int day_of_week( int date, int month, int year) { int

Write a C program that reads the customer number and power consumed and prints the amount to be paid by the customer.

An electric power distribution company charges its domestic consumers as follows. Consumption Rate of Units Charge ------------------------------------------------------ 0-200 Rs.0.50 per unit 201-400 Rs.100 plus Rs.0.65 per unit excess 200 401-600 Rs.230 plus Rs.0.80 per unit excess of 400. #include<stdio.h> #include<conio.h> void main() { int n, p; float amount; clrscr(); printf( "Enter the customer number: " ); scanf( "%d" ,&n); printf( "Enter the power consumed: " ); scanf( "%d" ,&p); if (p>=0 && p<=200) amount=p*0.50; else if (p>200 && p<400) amount = 100+((p-200) * 0.65); else if (p>400 && p<=600) amount = 230 + ((p-400) * 0.80); printf( "Amount to be paid by customer no. %d is Rs.:%5.2f." ,n,amount); getch(); } Output : Enter the customer number: 1 Enter the power consumed: 100 Amount to be paid by customer no. 1 is Rs.:50.00.