Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions 2D_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by ankit on 12-09-2019.
//

#include <bits/stdc++.h>
using namespace std;

int main()
{
int row, col;
cin >> row >> col;
vector< vector <int> >v;
v.resize(col,vector<int>(row));

for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cin >> v[i][j];
}
}

for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cout << v[i][j] << " ";
}
cout << endl;
}
}
37 changes: 18 additions & 19 deletions Age_Calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
//Program to check your age till date


#include<iostream.h>
#include<conio.h>
void main()
#include <iostream>
using namespace std;
int main()
{
int birth_month,birth_year;
int current_month,current_year;
int ageinyear,ageinmonth;
cout<<"Age Calculator\n\n";
int birth_month, birth_year;
int current_month, current_year;
int ageinyear, ageinmonth;
cout << "Age Calculator\n\n";

cout<<"\nEnter Your Birth Month(Eg:8): ";
cin>>birth_month;
cout<<"\nEnter Your Birth Year(Eg:1999): ";
cin>>birth_year;
cout << "\nEnter Your Birth Month(Eg:8): ";
cin >> birth_month;
cout << "\nEnter Your Birth Year(Eg:1999): ";
cin >> birth_year;

cout<<"\nEnter The Current Month(Eg:12): ";
cin>>current_month;
cout<<"\nEnter The Current Year(Eg:2020): ";
cin>>current_year;
ageinyear= ;
ageinmonth= ;
cout<<"\n\nYour Age is "<<ageinyear<<" Years And "<<ageinmonth<<" Months ";
getch();
cout << "\nEnter The Current Month(Eg:12): ";
cin >> current_month;
cout << "\nEnter The Current Year(Eg:2020): ";
cin >> current_year;
ageinyear = current_year - birth_year;
ageinmonth = 12 - birth_month;
cout << "\n\nYour Age is " << ageinyear << " Years And " << ageinmonth << " Months ";
}
41 changes: 38 additions & 3 deletions Calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
//Basic Calculator using C++

# include <iostream>
#include <cmath>
using namespace std;

template <typename T, typename U>
T find_max(T a, U b)
{
return a > b ? a : b;
}
int main()
{
int ch,sum;
int ch;
float sum, sub, mul, div,max;
int mod;
float num1, num2;
cout << "Enter option \n 1.Addition \t 2. Subtraction \n 3.Multiplication \t 4. Division \n 5. Modulus \t 6. Maximum of two nos \n ";
cin >> ch;
Expand All @@ -13,9 +22,35 @@ int main()
switch(ch)
{
case 1:
sum=num1+num2;
cout<<"Sum of two numbers is "<<sum;
sum = num1 + num2;
cout << "Sum of two numbers is " << sum;
break;

case 2:
sub = (num1 - num2);
cout << "Difference of two numbers is " << sub;
break;

case 3:
mul = num1 * num2;
cout << "Product of two numbers is " << mul;
break;

case 4:
div = num1 / num2;
cout << "Division of two numbers is " << div;
break;

case 5:
mod = fmod(num1, num2);
cout << "Modulus of two number is " << mod;
break;

case 6:
max = find_max(num1, num2);
cout << "Maximum number is " << max;
break;

default:
// If the options is not 1-6, error message is shown
cout << "Error! Option is not correct";
Expand Down
6 changes: 6 additions & 0 deletions CheckCharacter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# A program to check if the a character is a Capital Letter, Small Letter,vowel,consonant, Digit or special Character .

ch = input("Enter a character: ") #character input
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is a Special Character")
155 changes: 149 additions & 6 deletions Seriesplay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Print the following Series using a menu driven program
//Print the following Series using a menu driven program
//1. Fibonacci series
//2. n natural numbers
//3. n prime numbers
Expand All @@ -10,27 +10,170 @@
//7. 1+2+6+24+120+.....
//8. 1/2+2/3+3/4+4/5+....

# include <iostream>
#include <iostream>
using namespace std;

int fib(int n)
{
if (n == 0 || n == 1)
return 1;
else
return fib(n - 1) + fib(n - 2);
}

void natural(int n)
{
for (int i = 1; i <= n; ++i)
{
cout << i << " ";
}
cout << endl;
}

bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;

return true;
}
void printPrime(int n)
{
for (int i = 2; i <= n; i++) {
if (isPrime(i))
cout << i << " ";
}
}

void even_number(int n)
{
for (int i = 0; i <= n; i = i + 2)
{
cout << i << " ";
}
cout << endl;
}

int createPalindrome(int input, int b, bool isOdd)
{
int n = input;
int palin = input;
if (isOdd)
n /= b;
while (n > 0)
{
palin = palin * b + (n % b);
n /= b;
}
return palin;
}
void generatePalindromes(int n)
{
int number;
for (int j = 0; j < 2; j++)
{
int i = 1;
while ((number = createPalindrome(i, 10, j % 2)) < n)
{
cout << number << " ";
i++;
}
}
}

void square_sum(int n)
{
int sum = 0;
for (int i = 1; i <= n; ++i)
{
sum += i * i;
}
cout << sum << endl;
}


int fact(int n)
{
if (n <= 0)
return 1;
else
return fact(n - 1) * n;
}

int sum_fact(int n)
{
int sum1 = 0;
for (int i = 1; i <= n; ++i)
{
sum1 += fact(i);
}
cout << sum1 << endl;
}

int series(int n)
{
int a = 1;
float sum_series = 0;
for (int i = 0; i < n; ++i)
{
sum_series += (float) a / (a + 1);
a++;
}
cout << sum_series << endl;
}
int main()
{
int ch;

cout << "Enter option \n";
cout<<"1. Print Fibonacci series\n";
cout<<"2. n natural numbers\n";
cout<<"3. n prime numbers\n";
cout<<"4. n even numbers\n";
cout<<"5. n pallindrome numbers\n";
cout<<"6. 1+4+9+16+.....n";
cout<<"6. 1+4+9+16+.....\n";
cout<<"7. 1+2+6+24+120+.....\n";
cout<<"8. 1/2+2/3+3/4+4/5+....\n";
cin >> ch;

int n1;
cin >> n1;
switch(ch)
{
case 1:

cout << fib(n1);
break;

case 2:
natural(n1);
break;

case 3:
printPrime(n1);
break;

case 4:
even_number(n1);
break;

case 5:
generatePalindromes(n1);
break;

case 6:
square_sum(n1);
break;

case 7:
sum_fact(n1);
break;

case 8:
series(n1);
break;

default:
// If the options is not 1-8, error message is shown
cout << "Error! Option is not correct";
Expand Down
34 changes: 34 additions & 0 deletions binary_search1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by ankit on 07-08-2019.
//

#include <bits/stdc++.h>
using namespace std;

typedef int ll;

int main(void)
{
ll n, x;
cin >> n >> x;
vector <ll> v;
ll input;
for (int i = 0; i < n; i++)
{
cin >> input;
v.push_back(input);
}
ll k = 0;
for (int b = n / 2; b >= 1; b /= 2)
{
while (k + b < n && v[k + b] <= x)
k += b;
}

if (v[k] == x)
{
cout << "Element found at " << k + 1 << endl;
}
else
cout << "No element found" << endl;
}
Loading