Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hacktoberfest #120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions checkleapyear.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
using namespace std;

int main() {

int year;
cout << "Enter a year: ";
cin >> year;

// leap year if perfectly divisible by 400
if (year % 400 == 0) {
cout << year << " is a leap year.";
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
cout << year << " is not a leap year.";
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
cout << year << " is a leap year.";
}
// all other years are not leap years
else {
cout << year << " is not a leap year.";
}

return 0;
}
20 changes: 20 additions & 0 deletions palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main()
{
int n,r,sum=0,temp;
cout<<"Enter the Number=";
cin>>n;
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
cout<<"Number is Palindrome.";
else
cout<<"Number is not Palindrome.";
return 0;
}
121 changes: 121 additions & 0 deletions reversingqueue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include <bits/stdc++.h>
using namespace std;

void printQueue(queue<long long int> Queue)
{
while (!Queue.empty()) {
cout << Queue.front() << " ";
Queue.pop();
}
}

void revQueue(queue<long long int>& q)
{
if (q.empty())
return;

long long int data = q.front();
q.pop();

revQueue(q);

q.push(data);
}

int main()
{
queue<long long int> Queue;
Queue.push(1);
Queue.push(2);
Queue.push(3);
Queue.push(4);
Queue.push(5);
revQueue(Queue);
printQueue(Queue);
}
// Java program to reverse a Queue by recursion
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

// Java program to reverse a queue recursively
class Queue_reverse {

static Queue<Integer> queue;

// Utility function to print the queue
static void Print()
{
while (!queue.isEmpty())
{
System.out.print(queue.peek() + " ");
queue.remove();
}
}

// Recurrsive function to reverse the queue
static Queue<Integer> revQueue(Queue<Integer> q)
{
// Base case
if (q.isEmpty())
return q;

// Dequeue current item (from front)
int data = q.peek();
q.remove();

// Reverse remaining queue
q = revQueue(q);

// Enqueue current item (to rear)
q.add(data);

return q;
}

// Driver code
public static void main(String args[])
{
queue = new LinkedList<Integer>();
queue.add(1);
queue.add(2);
queue.add(3);
queue.add(4);
queue.add(5);
queue = revQueue(queue);
Print();
}
}
from queue import Queue


def revQueue(queue: Queue):

if queue.empty():
return

item = queue.queue[0]
queue.get()

revQueue(queue)

queue.put(item)


def print_queue(queue: Queue):
while not queue.empty():
print(queue.queue[0], end=" ")
queue.get()
print()


if __name__ == "__main__":
q = Queue()
q.put(1)
q.put(2)
q.put(3)
q.put(4)
q.put(5)

revQueue(q)
print_queue(q)
35 changes: 35 additions & 0 deletions roots.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <cmath>
using namespace std;

int main() {

float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;
cout << "Enter coefficients a, b and c: ";
cin >> a >> b >> c;
discriminant = b*b - 4*a*c;

if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}

else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
x1 = -b/(2*a);
cout << "x1 = x2 =" << x1 << endl;
}

else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
}

return 0;
}