0% found this document useful (0 votes)
7 views4 pages

Programs of PF C++

Uploaded by

7hammad86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Programs of PF C++

Uploaded by

7hammad86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Programs

1.Characters for the ASCII Codes


#include <iostream>
using namespace std;
int main () {
int i;
for (char i=32;i<=127;i++)
{
cout<<i;
}
return 0;
}
2.Sum of Numbers
#include <iostream>
using namespace std;
int main (){
int n,sum=0;
cout<<"enter a number :";
cin>>n;
for (int b=1;b<=n;b++)
{
cout<<b<<endl;
sum=sum+b;
}
cout<<sum;
return 0;
}
3. Distance Traveled
#include <iostream>
using namespace std;
int main (){
int speed,time;
cout<<"speed of vehicle in mph:";
cin>>speed;
cout<<"Time in Hours:";
cin>>time;
int distance;
for (int hour;hour<=time;++hour)
{
distance=speed*hour;
cout<<"distance travelled:"<<distance<<endl;
}
return 0;
}

4. Speed Conversion Chart


#include <iostream>
using namespace std;
int main ()
{
double constant=0.6214;
int start_speed=60,end_speed=130;
double mph;
for (int kph=start_speed;kph<=end_speed;kph+=5)
{
mph=kph*0.6214;
cout<<"kph:"<<kph<<"----> "<<"mph:"<< mph <<endl;
}
return 0;
}
5. Ocean Levels
#include <iostream>
using namespace std;
int main ()
{
double constant=3.1;
int n=25;
double total;
for (int year=1;year<=25;++year)
{
total+=constant;
cout<<"No. of year:"<<year<<"\n"<<"Ocean level increase:"<<total<<endl;
}
return 0;
}
6. Calories Burned
#include <iostream>
using namespace std;
int main ()
{
double constant=3.9;
int start=10,end=30,sum=0;
double total;
for (int cal=10;cal<=30;cal+=5)
{
total*=constant;
cout<<"No. of mint:"<<cal<<"\n"<<"Calories burned:"<<total<<endl;
}
return 0;
}
7. Membership Fees Increase
#include <iostream>
using namespace std;
int main ()
{
float n=2500;
int b;
b=2500*4/100;
for (int year=1;year<=6;++year)
{
cout<<"No. of year:"<<year<<endl;
n=n+b;
cout<<"total payment:"<<n<<endl;
}
return 0;
}
8. Diamond Display
#include <iostream>
using namespace std;
int main() {
int n = 4;
for (int i = 1; i <= n; ++i) {
for (int j = i; j < n; ++j) {
cout << " ";
}
for (int j = 1; j <= (2 * i - 1); ++j) {
cout << "+";
}
cout <<endl;
}
for (int i = n - 1; i >= 1; --i) {

for (int j = n; j > i; --j) {


cout << " ";
}
for (int j = 1; j <= (2 * i - 1); ++j) {
cout << "+";
}
cout << endl;
}
return 0;
}
9. Triangle Display

#include <iostream>
using namespace std;
int main() {
int height = 4;
for (int i = 1; i <= height; ++i) {
for (int j = 1; j <= (2 * i - 1); ++j) {
cout << "+";
}
cout << endl;
} for (int i = height - 1; i >= 1; --i) {
for (int j = 1; j <= (2 * i - 1); ++j) {
cout << "+";
}
cout << endl;
}
return 0;
}
10. Arrowhead Display
#include <iostream>
Using namespace std;
int main() {
int maxPlus = 13
for (int i = 1; i <= maxPlus; i += 2) {
for (int j = 0; j < (maxPlus - i) / 2; ++j) {
cout << " ";
}
for (int j = 0; j < i; ++j) {
cout << "+";
}
cout << endl;
}
for (int i = maxPlus - 4; i >= 1; i -= 2) {
for (int j = 0; j < (maxPlus - i) / 2; ++j) {
cout << " ";
}
for (int j = 0; j < i; ++j) {
cout << "+";
}
cout << endl;
}
return 0;
}

You might also like