An electric power distribution company charges its domestic consumers as follows:
Consumption Units Rate of 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.
Write a C program that reads the customer number and power consumed and prints the amount to be paid by the customer. [Nov./Dec.-2005,Set-3, Unit-1, Q.No.-34]
Ans. : */
#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();
}
Write a program to read the values of x, y and z and print the results of the following expressions in one line.
Ans. :
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
float a,b,c;
clrscr();
printf("Enter the values of x,y and z : ");
scanf("%d%d%d",&x,&y,&z);
a=(x+y+z)/(x-y-z);
b=(x+y+z)/3;
c=(x+y)*(x-y)*(y-z);
printf("a = %f\tb = %f\tc = %f",a,b,c);
getch();
}
Write a program to read a text file and convert the file contents in capital (Upper-case) and write the contents in a output file.
Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
a=toupper(a);
fputc(a,fp2);
}
while(a!=EOF);
fcloseall();
getch();
}
Write a program to copy the contents of one file into another. [June-2005, Set-4, Unit-5, Q.No.-2]
Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
fputc(a,fp2);
}
while(a!=EOF);
fcloseall();
getch();
}
Write a program to read the values of x, y and z and print the results of the following expressions in one line.
Ans. :
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
float a,b,c;
clrscr();
printf("Enter the values of x,y and z : ");
scanf("%d%d%d",&x,&y,&z);
a=(x+y+z)/(x-y-z);
b=(x+y+z)/3;
c=(x+y)*(x-y)*(y-z);
printf("a = %f\tb = %f\tc = %f",a,b,c);
getch();
}
Write a program to read a text file and convert the file contents in capital (Upper-case) and write the contents in a output file.
Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
a=toupper(a);
fputc(a,fp2);
}
while(a!=EOF);
fcloseall();
getch();
}
Write a program to copy the contents of one file into another. [June-2005, Set-4, Unit-5, Q.No.-2]
Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
fputc(a,fp2);
}
while(a!=EOF);
fcloseall();
getch();
}
No comments:
Post a Comment