Skip to content

Commit

Permalink
Add Till Arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonemumtaz committed Sep 27, 2024
0 parents commit 5d0b89f
Show file tree
Hide file tree
Showing 43 changed files with 995 additions and 0 deletions.
24 changes: 24 additions & 0 deletions NCRfunction.cpp
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;
}
20 changes: 20 additions & 0 deletions TAP2.cpp
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;
}
}
21 changes: 21 additions & 0 deletions TAP3.cpp
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;
}
}

25 changes: 25 additions & 0 deletions TAP4.cpp
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;
}
}
21 changes: 21 additions & 0 deletions TAP5.cpp
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;
}
}
21 changes: 21 additions & 0 deletions TAP6.cpp
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;
}
}
68 changes: 68 additions & 0 deletions arrays.cpp
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;
}
23 changes: 23 additions & 0 deletions bitwiseoperators.cpp
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;


}
28 changes: 28 additions & 0 deletions checkprimenumberusingfunctions.cpp
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;
}

}
10 changes: 10 additions & 0 deletions continuestatement.cpp
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;
}
}
21 changes: 21 additions & 0 deletions conversionofbinarytodecimal.cpp
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;
}
19 changes: 19 additions & 0 deletions conversionofdecimaltobinary.cpp
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;
}
20 changes: 20 additions & 0 deletions difficultpattern.cpp
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;
}
}
25 changes: 25 additions & 0 deletions evenoddfunction.cpp
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;
}
}
16 changes: 16 additions & 0 deletions fibonacciseries.cpp
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;
}
}
Loading

0 comments on commit 5d0b89f

Please sign in to comment.