-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5d0b89f
Showing
43 changed files
with
995 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
#include<iostream> | ||
using namespace std; | ||
int factorial(int n){ | ||
int fact=1; | ||
for(int i=1;i<=n;i++){ | ||
fact=fact*i; | ||
} | ||
return fact; | ||
} | ||
int nCr(int n, int r){ | ||
int numerator = factorial(n); | ||
int denominator=factorial(r)*factorial(n-r); | ||
int answer=numerator/denominator; | ||
return answer; | ||
} | ||
int main(){ | ||
|
||
int n,r; | ||
cout<<"enter n and r"<<endl; | ||
cin>>n>>r; | ||
|
||
cout<<"Answer is :"<<nCr(n,r)<<endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
char start = 'A' ; | ||
while (i <=n ) | ||
{ | ||
int j=1; | ||
while (j<=i){ | ||
cout<<start<< " " ; | ||
start++; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
char start = 'A' ; | ||
while (i <=n ) | ||
{ | ||
int j=1; | ||
while (j<=i){ | ||
char ch = ('A'+i+j-2); | ||
cout<<ch<< " " ; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
|
||
while (i<=n) | ||
{ | ||
int space = n-i; | ||
while (space) | ||
{ | ||
cout<<" "; | ||
space--; | ||
} | ||
int j=1; | ||
while (j<=i){ | ||
cout <<"*"; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
|
||
while (i <=n ) | ||
{ | ||
int j=1; | ||
char start = 'A' + n-i; | ||
while (j<=i){ | ||
cout<<start<< " " ; | ||
start++; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
|
||
while (i<=n) | ||
{ | ||
char star = n-i; | ||
cout<<" "; | ||
int j=1; | ||
while (j<=i){ | ||
cout <<"*"; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
using namespace std; | ||
void printarray(int arr[], int size) | ||
{ | ||
cout << "printing the array elements:" << endl; | ||
for (int i = 0; i <= size; i++) | ||
{ | ||
cout << arr[i] << " "; | ||
} | ||
cout << "printing done" << endl; | ||
} | ||
int main() | ||
{ | ||
int number[15]; | ||
cout << "value at 14 index is:" << number[14] << endl; | ||
|
||
// initializing an array | ||
int second[3] = {5, 7, 11}; | ||
// accessing an element | ||
cout << "value at second index:" << second[2] << endl; | ||
int third[15] = {2, 7}; | ||
|
||
printarray(third, 15); | ||
|
||
int n = 15; | ||
// cout << "printing the array elements:" << endl; | ||
// for (int i = 0; i <= n; i++) | ||
// { | ||
// cout << third[i] << " "; | ||
// } | ||
// intialixing all locations with 0 | ||
int fourth[10] = {0}; | ||
int m = 10; | ||
printarray(fourth, 10); | ||
// print the array elements | ||
// cout << "printing the array elements:" << endl; | ||
// for (int i = 0; i <= m; i++) | ||
// { | ||
// cout << fourth[i] << " "; | ||
// } | ||
|
||
// intialixing all locations with 1 (not possible with below line) | ||
int fifth[10] = {1}; | ||
int x = 10; | ||
printarray(fifth, 10); | ||
// cout << "printing the array elements:" << endl; | ||
// for (int i = 0; i <= x; i++) | ||
// { | ||
// cout << fifth[i] << " "; | ||
// } | ||
int fifthsize = sizeof(fifth) / sizeof(int); | ||
cout << "size of fifth is:" << fifthsize << endl; | ||
char ch[5] = {'a', 'b', 'c', 'd', 'e'}; | ||
cout << ch[4] << endl; | ||
|
||
cout << "printing the array elements:" << endl; | ||
for (int i = 0; i <= 5; i++) | ||
{ | ||
cout << ch[i] << " "; | ||
} | ||
cout << "printing done" << endl; | ||
|
||
double firstdouble[5]; | ||
float firstfloat[6]; | ||
bool firstbool[9]; | ||
|
||
cout << "everything is alright" << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int a= 4; | ||
int b = 6; | ||
cout <<"a & b ="<< (a&b)<<endl; | ||
cout <<"a | b ="<< (a|b)<<endl; | ||
cout <<"~a ="<< (~a)<<endl; | ||
cout <<"a ^ b ="<< (a^b)<<endl; | ||
cout<<(17>>2)<<endl; | ||
cout<<(17>>1)<<endl; | ||
cout<<(19<<1)<<endl; | ||
cout<<(19<<2)<<endl; | ||
cout<<(5<<2)<<endl; | ||
|
||
int i = 7 ; | ||
cout<< (++i) <<endl; | ||
cout<< (i++) <<endl; | ||
cout<< (i--) <<endl; | ||
cout<< (--i) <<endl; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#include<iostream> | ||
using namespace std; | ||
//1--> prime number | ||
//0-->not ba prime number | ||
bool isprime(int n){ | ||
for(int i=2;i<=n;i++){ | ||
if(n%i==0){ | ||
return 0; | ||
} | ||
else{ | ||
return 1; | ||
} | ||
} | ||
} | ||
int main(){ | ||
|
||
int num; | ||
cout<<"enter the number:"<<endl; | ||
cin>>num; | ||
if (isprime(num)){ | ||
cout<<"the given number is a prime number"<<endl; | ||
} | ||
else{ | ||
cout<<"the given number is odd number"<<endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
for(int i=1;i<=5;i++){ | ||
cout<<"hi"<<endl; | ||
cout<<"Hey"<<endl; | ||
continue; | ||
cout<<"Reply toh karde"<<endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
int main() { | ||
int n; | ||
cout << "Enter the value of n: " << endl; | ||
cin >> n; | ||
int answer = 0; | ||
int i = 0; | ||
while (n != 0) { | ||
int digit=n%10; | ||
if(digit==1){ | ||
answer = answer+ pow(2,1); | ||
|
||
} | ||
n=n/10; | ||
i++; | ||
} | ||
cout<<"answer is:"<<answer<<endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n; | ||
cout << "enter the value of n" << endl; | ||
cin >> n; | ||
int answer = 0; | ||
int i = 0; | ||
while (n != 0) | ||
{ | ||
int bit = n & 1; | ||
answer = (bit * pow(10, i)) + answer; | ||
n = n >> 1; | ||
i++; | ||
} | ||
cout << "answer is:" << answer << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int i = 1; | ||
while (i <=n ) | ||
{ | ||
int j=1; | ||
int value=i; | ||
while (j<=i){ | ||
cout<<value<< " " ; | ||
value++; | ||
j=j+1; | ||
} | ||
cout<<endl; | ||
i=i+1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
#include<iostream> | ||
using namespace std; | ||
//1 --> even | ||
//0 --> odd | ||
bool iseven(int a){ | ||
//odd | ||
if(a %2!=0) | ||
return 0; | ||
else{ | ||
return 1; | ||
} | ||
} | ||
int main(){ | ||
|
||
int num; | ||
cout<<"enter the number:"<<endl; | ||
cin>>num; | ||
if (iseven(num)){ | ||
cout<<"numer is even"<<endl; | ||
} | ||
else { | ||
cout<<"number is odd"<<endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main(){ | ||
int n; | ||
cout<<"enter the value of n"<<endl; | ||
cin>>n; | ||
int a= 0; | ||
int b= 1; | ||
cout<<a<<" "<<b<<" "; | ||
for(int i=1;i<=n;i++){ | ||
int nextnumber=a+b; | ||
cout<<nextnumber<<" "; | ||
a=b; | ||
b=nextnumber; | ||
} | ||
} |
Oops, something went wrong.