Skip to content

Commit 0024e55

Browse files
Add files via upload
1 parent 14d3b82 commit 0024e55

11 files changed

+300
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n,no=1;
7+
cout<<"Enter how many numbers cube you want: "<<endl;
8+
cin>>n;
9+
while(no<=n)
10+
{
11+
cout<<"Cube of "<<no<<" = "<<no*no*no<<endl;
12+
no++;
13+
}
14+
15+
return 0;
16+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
long long int n,no=2;
7+
cout<<"From 2 to how many numbers do you want even numbers : "<<endl;
8+
cin>>n;
9+
cout<<"List of even numbers from 2 to "<<n<<" :";
10+
while(no<=n)
11+
{
12+
cout<<no<<endl;
13+
no=no+2;
14+
}
15+
16+
return 0;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
long long int a,b,c,n;
7+
a=0; b=1;
8+
cout<<"Enter number of terms (n) = ";
9+
cin>>n;
10+
cout<<"Fibonacci series is "<<endl;
11+
if(n==1){
12+
cout<<"0 ";
13+
}else if(n==2){
14+
cout<<a<<" "<<b<<" ";
15+
}else{
16+
cout<<a<<" "<<b<<" ";
17+
long int count=3;
18+
while(count<=n)
19+
{
20+
c=a+b;
21+
cout<<c<<" ";
22+
a=b;
23+
b=c;
24+
count++;
25+
}
26+
}
27+
return 0;
28+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
long int num,z,rev=0,rem;
7+
cout<<"Enter a number = "<<endl;
8+
cin>>num;
9+
z=num;
10+
while(num>0)
11+
{
12+
rem=num%10;
13+
num=num/10;
14+
rev=(rev*10)+rem;
15+
}
16+
if(rev==z){
17+
cout<<"Given number is Palindrome";
18+
}else{
19+
cout<<"Given number is not Palindrome";
20+
}
21+
22+
return 0;
23+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
#include<iomanip>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
long long int num,i=1,prod;
8+
cout<<"Enter number who's table you want : "<<endl;
9+
cin>>num;
10+
cout<<"Table of "<<num<<" :0"<<endl;
11+
do{
12+
prod = num * i;
13+
cout<<num<<" X "<<setw(2)<<i<<" = "<<prod<<endl;
14+
i = i+1;
15+
}while(i<=10);
16+
cout<<"End of table";
17+
18+
return 0;
19+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
long int num,sum=0;
8+
cout<<"Enter how many number of terms you want to enter: "<<endl;
9+
cin>>n;
10+
cout<<"Enter numbers now :"<<endl;
11+
for(int i=0; i<n; i++)
12+
{
13+
cin>>num;
14+
sum = sum + num;
15+
}
16+
float avg = float(sum)/n;
17+
cout<<"Average = "<<avg<<endl;
18+
19+
return 0;
20+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
#include<math.h>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int n;
8+
float x, sum=0.0;
9+
cout<<"Enter how many terms : "<<endl;
10+
cin>>n;
11+
cout<<"Enter the value of x : "<<endl;
12+
cin>>x;
13+
float z=x/(x+1);
14+
for(int i=1;i<=n;i++)
15+
{
16+
sum=sum+pow(z,i)*1/i;
17+
}
18+
cout<<"Sum of Series = "<<sum;
19+
20+
return 0;
21+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//You can see explanation of program in last of the program see its important
2+
#include<iostream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int n;
8+
cout<<"Enter how many lines : ";
9+
cin>>n;
10+
for(int i=1;i<=n;i++)
11+
{
12+
for(int j=1;j<=i;j++)
13+
{
14+
cout<<i<<" "; // if you print j here then series will be 1\n 1 2\n 1 2 3\n 1 2 3 4 like this
15+
}
16+
cout<<endl;
17+
}
18+
19+
return 0;
20+
}
21+
22+
/*
23+
On execution we input ythe number of lines n (say 4).
24+
In this program the inner j loop is nested inside the outer i loop.
25+
For each value of variable i of outer loop, the inner loop will be executed completely.
26+
For 1st iteration of outer loop, the inner loop will be executed completely.
27+
For 1st iteration of outer loop, the i is initialized to 1 and inner loop is executed once as the condition (j<=i) ,
28+
is satisfied only once, thus prints the value of i (i.e. 1) once.
29+
the statement cout<<"\n" must be outside the inner loop and inside the outer loop in order to produce exactly one
30+
line for each iteration of outer loop.
31+
On second iteration(pass) of outer loop, when i=2 then inner loop executes 2 times and thus displaying value of i (i.e 2)
32+
2 times and process will continue until the condition in the loop becomes false.
33+
*/
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//You can see the use of break statement also here
2+
#include<iostream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
long long int a,b,operation;
8+
cout<<"Enter two numbers :"<<endl;;
9+
cin>>a>>b;
10+
cout<<"1. Addition"<<endl;
11+
cout<<"2. Subtraction"<<endl;
12+
cout<<"3. Multiplication"<<endl;
13+
cout<<"4. Division"<<endl;
14+
cout<<"5. Modulus"<<endl;
15+
cout<<"Select appropriate number for appropriate operation :"<<endl;
16+
int choice;
17+
cin>>choice;
18+
switch(choice)
19+
{
20+
case 1:
21+
operation=a+b;
22+
cout<<" Addition = "<<operation;
23+
break;
24+
case 2:
25+
operation=a-b;
26+
cout<<" Subtraction = "<<operation;
27+
break;
28+
case 3:
29+
operation=a*b;
30+
cout<<" Multiplication = "<<operation;
31+
break;
32+
case 4:
33+
operation=a/b;
34+
cout<<" Division = "<<operation;
35+
break;
36+
case 5:
37+
operation=a%b;
38+
cout<<" Modulus = "<<operation;
39+
break;
40+
default:
41+
cout<<"Invalid Choice";
42+
}
43+
44+
return 0;
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int a,b;
7+
char ch;
8+
do{
9+
cout<<"Enter Divident"<<endl;
10+
cin>>a;
11+
cout<<"Enter Divisor"<<endl;
12+
cin>>b;
13+
if(b==0)
14+
{
15+
cout<<"Illegal Divisor"<<endl;
16+
continue;
17+
}
18+
cout<<"Quotient =\t"<<a/b<<endl;
19+
cout<<"Remainder =\t"<<a%b<<endl;
20+
cout<<"Want to Continue ? (y/n):";
21+
cin>>ch;
22+
} while(ch=='Y' || ch=='y');
23+
24+
return 0;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//Lets see functional (recursion) appproach for this problem:
2+
3+
#include<iostream>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
long long int fact(int);
9+
int num;
10+
cout<<"Enter a number who 's factorial you want : "<<endl;
11+
cin>>num;
12+
cout<<"Factorial = "<<fact(num);
13+
14+
return 0;
15+
}
16+
17+
long long int fact(int x)
18+
{
19+
long long int prod = 1;
20+
if(x==0 || x==1)
21+
{
22+
prod = 1;
23+
}else
24+
{
25+
for(int i=2; i<=x; i++)
26+
{
27+
prod = x *fact(x-1);
28+
}
29+
}
30+
return (prod);
31+
32+
}
33+
34+
35+
36+
37+
// It is a iterative approach to solve this problem
38+
// #include<iostream>
39+
// using namespace std;
40+
41+
// int main()
42+
// {
43+
// long long int n,fact=1;
44+
// cout<<"Enter number who's factorial you want"<<endl;
45+
// cin>>n;
46+
// for(int i=1;i<=n;i++)
47+
// {
48+
// fact=fact*i;
49+
// }
50+
// cout<<"Factorial of number "<<n<<" = "<<fact;
51+
52+
// return 0;
53+
// }

0 commit comments

Comments
 (0)