0% found this document useful (0 votes)
95 views3 pages

C++ Programs for Math and Patterns

The document contains multiple C++ code snippets that demonstrate various programming concepts like: 1) A program that calculates the factorial of a user-input number using a while loop. 2) A program that calculates bonus and total salary for numbers above and below a threshold. 3) A program that calculates the sum of a series of fractions by iterating in increments of 3 using while loop. 4) A program that calculates the sum of powers of a number using a while loop. 5) A program that converts a number to character using casting. 6) A program that prints a pattern of increasing stars using nested for loops.

Uploaded by

Ammar Khalid
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)
95 views3 pages

C++ Programs for Math and Patterns

The document contains multiple C++ code snippets that demonstrate various programming concepts like: 1) A program that calculates the factorial of a user-input number using a while loop. 2) A program that calculates bonus and total salary for numbers above and below a threshold. 3) A program that calculates the sum of a series of fractions by iterating in increments of 3 using while loop. 4) A program that calculates the sum of powers of a number using a while loop. 5) A program that converts a number to character using casting. 6) A program that prints a pattern of increasing stars using nested for loops.

Uploaded by

Ammar Khalid
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

#include<iostream>

using namespace std;


int main()
{
int a,b=1,c=1;
cout<<" enter fictorial you wnt"<<endl;
cout<<"enter number =";
cin>> a;
while(b<=a)
{
c=c*b;
b++;
}
cout<<"fictorial of ="<<c<<endl;
system("pause");
return 0;
}

Largest number

#include<iostream>
using namespace std;
int main()
{
double a,b,c=0;
cout<<"enter salary = ";
cin>> a;
if(a>10000)
{ cout<<"your salary is !!!!!"<<endl;
b= a/10000*100;
cout<< " your bonus is = "<< b<<endl;
c=a+b;
cout<<" your salary will be = "<<c<<endl;
}
else
{
cout<<a;
}
system("pause");
return 0;
}

Trhrhrhtrhyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

#include <iostream>
using namespace std;

int main()
{
int b=0;
cout<<"enter number"<<endl;
while(b<30)
{
b=b+3;
cout<<"1/"<<b<<" + ";
}
system("pause");
return 0;
}

#include <iostream>
using namespace std;

int main()
{
float c=0;
float b=3;
while(b<10)
{
cout<<"1/"<<b<<"+"<<endl;
c=c+1/b;
b=b+3;
}
cout<<"sum is"<<c;
system("pause");
return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b=1,c=0;
cout<<"enter number";
cin>>a;
while(b<=5)
{
c=c+pow(a,b);
b++;
}
cout<<"answer is"<<c;

system("pause");
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
if(a>9){
cout<<static_cast<char>(a+55)<<endl;
}
else{
cout<<a;
}

system("pause");
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int x, y,space;
cout << "star"<<endl;
for (x =1; x<=5; x++)
{
for (y =1; y<=5-x;y++)
cout<<" ";
for(space=1;space<=2*x-1;space++)
cout<<" "<<'*';
cout<<endl;
}

system("pause");
return 0;
}

You might also like