PF Programs
PF Programs
His
dearness allowance is 40% of basic salary, and house rent
allowance is 20% of basic salary. Write a program to calculate his
gross salary.
PROGRAM:
#include<stdio.h>
int main()
scanf(“%f”,&BSal);
DAllow=BSal * .40;
HRent=BSal * .20;
return(0);
Q-2. The distance between two cities (in km.) is input through the
keyboard. Write a program to convert and print this distance in
meters, feet, inches and centimeters.
PROGRAM:
#include<stdio.h>
int main()
{
float DKM,DM,DF,DI,DCM;
scanf("%f",&DKM);
DM = DKM * 1000;
DF = DM * 3,28;
DI = DF * 12;
DCM= DI * 2.5;
system("CLS");
return(0);
#include<iostream>
int main()
float S1,S2,S3,S4,S5,Obtained,Per;
printf("Enter Students Marks in Five Subjects = ");
scanf("%f %f %f %f %f",&S1,&S2,&S3,&S4,&S5);
Obtained=S1+S2+S3+S4+S5;
Per=Obtained/500*100;
system("CLS");
return(0);
#include<stdio.h>
using namespace std;
int main()
{
clrscr();
float celsius,fahrenhiet;
printf("Enter Temperature in celsius=");
scanf("%f",&celsius);
//fahrenhiet=(9/5)*celsius+32;
fahrenhiet=(9*celsius)/5+32;
printf("\nTemperature In Fahrenheit is=%f",fahrenhiet);
return(0);
}
Q-5. The length & breadth of a rectangle and radius of a circle are
input through the keyboard. Write a program to calculate the area
& perimeter of the rectangle, and the area & circumference of the
circle.
#include <stdio.h>
using namespace std;
int main()
{ float L,B,R,RA,RP,CA,CC;
printf("Enter Length and Breadth of Rectangle and Radius of
Circle: ");
scanf("%f %f %f",&L,&B,&R);
RA=L*B;
RP=2*(L+B);
CA=3.14 * R * R;
CC=2 * 3.14 * R;
printf("Area of Rectangle = %.2f\n",RA);
printf("Perimeter of Rectangle = %.2f\n",RP);
printf("Area of Cicle = %.2f\n",CA);
printf("Circumference of Circle = %.2f\n",CC);
return(0);
}
Q-6. Two numbers are input through the keyboard into two
locations C and D. Write a program to interchange the contents of
C and D.
#include <stdio.h>
using namespace std;
int main()
{ int C,D,T;
printf("Enter two integer number:");
scanf("%d %d",&C,&D);
T=C;
C=D;
D=T;
printf("First New Number = %d\n",C);
printf("Second New Number = %d\n",D);
return(0);
}
(a) write a program to calculate the sum of its digits. (Hint: Use
the modulus operator ‘%’)
Q-7(a)
# include <stdio.h>
using namespace std;
int main()
{
long int N,S=0;
printf("Enter the five digit number=");
scanf("%ld",&N);
S=S+N%10;
N=N/10;
S=S+N%10;
N=N/10;
S=S+N%10;
N=N/10;
S=S+N%10;
N=N/10;
S=S+N;
printf("Sum of Digits of number = %ld\n\n",S);
return(0);
}
------------------------------------------- -----------------------------
Q-7 (b) If a five-digit number is input through the keyboard, write a
program to reverse the number.
Q-7(b)
# include <iostream>
using namespace std;
int main()
{ long int R=0,N;
printf("Enter the five digit number=");
scanf(“%ld”,&N);
R=N%10*10000;
N=N/10;
R=R+N%10*1000;
N=N/10;
R=R+N%10*100;
N=N/10;
R=R+N%10*10;
N=N/10;
R=R+N;
printf("Reverse number= %ld",R);
return(0);
}
Q-8. If a four-digit number is input through the keyboard, write a
program to obtain the sum of the first and last digit of this number.
# include <stdio.h>
using namespace std;
int main()
{
int N,S=0;
printf("Enter the four digit number=");
scanf("%d",&N);
S=S+N%10;
N=N/10;
N=N/10;
N=N/10;
S=S+N;
printf("Sum of first and last Digits= %d",S);
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{ int Amount,H,F,T;
printf("Enter Amount to be drawn :");
scanf("%d",&Amount);
H=Amount/100;
Amount=Amount - H * 100;
F=Amount/50;
Amount=Amount - F * 50;
T=Amount/10;
printf("\nNumber of 100 Notes = %d",H);
printf("\nNumber of 50 Notes = %d",F);
printf("\nNumber of 10 Notes = %d",T);
return(0);
}
Q-10. If the total selling price of 15 items and the total profit
earned on them is input through the keyboard, write a program to
find the cost price of one item.
#include<stdio.h>
using namespace std;
int main()
{ float SP,Profit,CP,Item_CP;
printf("Enter Selling Price of 15 items :");
scanf("%f",&SP);
printf("Enter Profit Earned on 15 items :");
scanf("%f",&Profit);
CP=SP-Profit;
Item_CP=CP/15;
printf("\nCost Price of One Item = %.2f",Item_CP);
return(0);
}
==========================================================================
#include<stdio.h>
using namespace std;
int main()
{
int N1,N2,L;
printf("Enter Two Integer values please : ");
scanf("%d %d",&N1, &N2);
if(N1>N2)
L=N1;
else
L=N2;
printf("Larger Value = %d",L);
return(0);
}
Q-12. Write a program, which will accept F.Sc Marks of a
student as inputs, find the percentage marks and using
percentage marks find whether the students is PASS or FAIL
#include<stdio.h>
using namespace std;
int main()
{
float Obtain,Per;
printf("Enter Obtain Marks of F,Sc = ");
scanf("%f",&Obtain);
Per = Obtain/1100 *100;
if(Per >= 50)
printf(“Student is PASS\n”);
else
printf(“Student is FAIL\n”);
return(0);
}
If his basic salary is less than Rs. 1500, then HRA = 10% of basic
salary and DA = 90% of basic salary. If his salary is either equal to
or above Rs. 1500, then HRA = Rs. 500 and DA = 98% of basic
salary. If the employee's salary is input through the keyboard write
a program to find his gross salary.
#include<stdio.h>
using namespace std;
int main()
{
float bs,gs,da,hra;
printf("Enter basic salary please : ");
scanf("%f",&bs);
if(bs<1500)
{
hra=bs*10/100;
da=bs*90/100;
}
else
{
hra=500;
da=bs*98/100;
}
gs=bs+hra+da;
printf("Gross Salary = Rs %f",gs);
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{
int m1,m2,m3,m4,m5;
float per;
printf("Enter Marks of student in five subjects : ");
scanf("%d %d %d %d %d",&m1,&m2,&m3,&m4,&m5);
per=(m1+m2+m3+m4+m5)/500.0 * 100;
if(per>=60)
printf("You Got First Division\n");
else
{
if(per>=50)
printf("You Got Second Division\n");
else
{
if(per>=40)
printf("You Got Third Division\n");
else
printf("You are Failed\n");
}
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{
char sex,ms;
int Age;
printf("Enter Age, Sex, marital status of driver : ");
scanf("%d %c %c",&Age,&sex,&ms);
if(ms == 'M')
printf("Driver is insured");
else
{
if(sex == 'M')
{
if (Age > 30)
printf("Driver is insured");
else
printf("Driver is not insured");
}
else
{
if(Age > 25)
printf("Driver is insured");
else
printf("Driver is not insured");
}
}
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{
int m1,m2,m3,m4,m5;
float per;
printf("Enter Marks of student in five subjects : ");
scanf("%d %d %d %d %d",&m1,&m2,&m3,&m4,&m5);
per=(m1+m2+m3+m4+m5)/500.0 * 100;
if(per>=60)
printf("You Got First Division\n");
if(per>=50 && per<60)
printf("You Got Second Division\n");
if(per>=40 && per<50)
printf("You Got Third Division\n");
if(per<40)
printf("You are Failed\n");
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{
char sex,ms;
int Age;
printf("Enter Age, Sex, marital status of driver : ");
scanf("%d %c %c",&Age,&sex,&ms);
if(ms == 'M' || ms == 'U' && sex == ‘M’ && Age >=30 || ms == 'U'
&& sex == ‘F’ && Age >=25)
printf("Driver is insured");
else
printf("Driver is not insured");
return(0);
}
#include<stdio.h>
#include<conio.h>
int main()
{
float cost_price, selling_price, profit, loss;
printf("Enter the cost price of an item: ");
scanf("%f", &cost_price);
printf("Enter the selling price of an item: ");
scanf("%f", &selling_price);
if (selling_price > cost_price) //here we get profit on selling item
{
//calculate profit via selling price - cost price
profit = selling_price - cost_price;
printf("We earn %.2f profit by selling item.", profit);
else
if (selling_price < cost_price) //here we get loss on selling item
{
//calculate loss via cost price - selling price
loss = cost_price - selling_price;
printf("\nWe incurred %.2f loss on selling item.", loss);
}
else
//here we don't get any loss and profit on selling item when (cost price == selling price)
{
printf("\nWe don't get any loss and profit on selling item");
}
}
#include<stdio.h>
using namespace std;
int main()
{ int N;
printf("Enter an Integer : ");
scanf("%d",&N);
if((N%2)==0)
printf("\n%d is an EVEN Integer", N);
else
printf("\n%d is an ODD Integer", N);
return(0);
}
======================================================================
#include<iostream>
using namespace std;
int main()
{
long int N,j,F;
cout<<"Enter the number=";
cin>>N;
F=1;
for(j=N;j>=1;j--)
F=F*j;
cout<<"factorial="<<F<<endl;
return(0);
}
#include<iostream>
using namespace std;
int main()
{
long int N,P,j,R;
cout<<"Enter the number and its power=";
cin>>N>>P;
R=1;
for(j=1;j<=P;j++)
R=R*N;
cout<<"Power Value="<<R<<endl;
return(0);
}
#include<iostream>
using namespace std;
int main()
{
int j,N,S;
S=0;
cout<<"Enter the value of N =";
cin>>N;
for(j=1;j<=N;j++)
{
S=S+j;
cout<<j<<endl;
}
cout<<"=============\n"<<S;
return(0);
}
*
**
***
****
*****
******
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=6;i++)
{
for(j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
return(0);
}
0
-1
--2
---3
----4
-----5
------6
-------7
--------8
---------9
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=0;i<=9;i++)
{
for(j=1;j<=i;j++)
cout<<" ";
cout<<i<<endl;
}
return(0);
}
====================================================================