forked from vinay-kumar99/Hactoberfest2022
-
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
Showing
9 changed files
with
348 additions
and
350 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 |
---|---|---|
@@ -1,25 +1,25 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int num,temp; | ||
cin>>num; | ||
temp=num; | ||
int sum=0; | ||
while(temp!=0) | ||
{ | ||
int x=temp%10; | ||
sum=sum+x; | ||
temp/=10; | ||
} | ||
if(num%sum==0) | ||
{ | ||
cout<<"Harshad Number"; | ||
} | ||
else | ||
cout<<"Not a Harshad NUmber"; | ||
return 0; | ||
} | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int num,temp; | ||
cin>>num; | ||
temp=num; | ||
int sum=0; | ||
while(temp!=0) | ||
{ | ||
int x=temp%10; | ||
sum=sum+x; | ||
temp/=10; | ||
} | ||
if(num%sum==0) | ||
{ | ||
cout<<"Harshad Number"; | ||
} | ||
else | ||
cout<<"Not a Harshad NUmber"; | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
#include <bits/stdc++.h> | ||
#include<vector> | ||
using namespace std; | ||
|
||
int max(int a, int b) { return (a > b) ? a : b; } | ||
|
||
int knapSack(int W, int wt, int val, int n) | ||
{ | ||
|
||
if (n == 0 || W == 0) | ||
return 0; | ||
|
||
if (wt[n] > W) | ||
return knapSack(W, wt, val, n - 1); | ||
|
||
else | ||
return max( | ||
val[n] + knapSack(W - wt[n], | ||
wt, val, n - 1), | ||
knapSack(W, wt, val, n - 1)); | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
int val,wt; | ||
cin>>val>>wt; | ||
int W = 400; | ||
int n = sizeof(val) / sizeof(val[0]); | ||
cout << knapSack(W, wt, val, n); | ||
return 0; | ||
} | ||
#include <bits/stdc++.h> | ||
#include<vector> | ||
using namespace std; | ||
|
||
int max(int a, int b) { return (a > b) ? a : b; } | ||
|
||
int knapSack(int W, int wt, int val, int n) | ||
{ | ||
|
||
if (n == 0 || W == 0) | ||
return 0; | ||
|
||
if (wt[n] > W) | ||
return knapSack(W, wt, val, n - 1); | ||
|
||
else | ||
return max( | ||
val[n] + knapSack(W - wt[n], | ||
wt, val, n - 1), | ||
knapSack(W, wt, val, n - 1)); | ||
} | ||
|
||
int main() | ||
{ | ||
|
||
int val,wt; | ||
cin>>val>>wt; | ||
int W = 400; | ||
int n = sizeof(val) / sizeof(val[0]); | ||
cout << knapSack(W, wt, val, n); | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,100 +1,100 @@ | ||
#include <stdio.h> | ||
|
||
#define MAX 50 | ||
int q[MAX]; | ||
int rear = - 1; | ||
int front = - 1; | ||
void insert() | ||
{ | ||
int add_item; | ||
if (rear == MAX - 1) | ||
printf("Queue Overflow \n"); | ||
else | ||
{ | ||
if (front == - 1) | ||
front = 0; | ||
printf("Inset the element in queue : "); | ||
scanf("%d", &add_item); | ||
rear = rear + 1; | ||
q[rear] = add_item; | ||
} | ||
} | ||
|
||
void delete() | ||
{ | ||
if (front == - 1 || front > rear) | ||
{ | ||
printf("Queue Underflow \n"); | ||
return ; | ||
} | ||
else | ||
{ | ||
printf("Element deleted from queue is : %d\n", q[front]); | ||
front = front + 1; | ||
} | ||
} | ||
void display() | ||
{ | ||
int i; | ||
if (front == - 1) | ||
printf("Queue is empty \n"); | ||
else | ||
{ | ||
printf("Queue is : \n"); | ||
for (i = front; i <= rear; i++) | ||
printf("%d ", q[i]); | ||
printf("\n"); | ||
} | ||
} | ||
void main() | ||
{ | ||
int choice; | ||
printf("1.Insert element to queue \n"); | ||
printf("2.Delete element from queue \n"); | ||
printf("3.Display all elements of queue \n"); | ||
printf("4.Quit \n"); | ||
do | ||
{ | ||
printf("Enter your choice : "); | ||
scanf("%d", &choice); | ||
switch (choice) | ||
{ | ||
case 1: | ||
insert(); | ||
break; | ||
case 2: | ||
delete(); | ||
break; | ||
case 3: | ||
display(); | ||
break; | ||
case 4: | ||
printf("EXIT"); | ||
} | ||
}while(choice!=4); | ||
} | ||
/* ""OUTPUT"" | ||
1.Insert element to queue | ||
2.Delete element from queue | ||
3.Display all elements of queue | ||
4.Quit | ||
Enter your choice : 1 | ||
Inset the element in queue : 10 | ||
Enter your choice : 1 | ||
Inset the element in queue : 20 | ||
Enter your choice : 1 | ||
Inset the element in queue : 30 | ||
Enter your choice : 3 | ||
Queue is : | ||
10 20 30 | ||
Enter your choice : 2 | ||
Element deleted from queue is : 10 | ||
Enter your choice : 2 | ||
Element deleted from queue is : 20 | ||
Enter your choice : 3 | ||
Queue is : | ||
30 | ||
Enter your choice : 4 | ||
EXIT | ||
*/ | ||
#include <stdio.h> | ||
|
||
#define MAX 50 | ||
int q[MAX]; | ||
int rear = - 1; | ||
int front = - 1; | ||
void insert() | ||
{ | ||
int add_item; | ||
if (rear == MAX - 1) | ||
printf("Queue Overflow \n"); | ||
else | ||
{ | ||
if (front == - 1) | ||
front = 0; | ||
printf("Inset the element in queue : "); | ||
scanf("%d", &add_item); | ||
rear = rear + 1; | ||
q[rear] = add_item; | ||
} | ||
} | ||
|
||
void delete() | ||
{ | ||
if (front == - 1 || front > rear) | ||
{ | ||
printf("Queue Underflow \n"); | ||
return ; | ||
} | ||
else | ||
{ | ||
printf("Element deleted from queue is : %d\n", q[front]); | ||
front = front + 1; | ||
} | ||
} | ||
void display() | ||
{ | ||
int i; | ||
if (front == - 1) | ||
printf("Queue is empty \n"); | ||
else | ||
{ | ||
printf("Queue is : \n"); | ||
for (i = front; i <= rear; i++) | ||
printf("%d ", q[i]); | ||
printf("\n"); | ||
} | ||
} | ||
void main() | ||
{ | ||
int choice; | ||
printf("1.Insert element to queue \n"); | ||
printf("2.Delete element from queue \n"); | ||
printf("3.Display all elements of queue \n"); | ||
printf("4.Quit \n"); | ||
do | ||
{ | ||
printf("Enter your choice : "); | ||
scanf("%d", &choice); | ||
switch (choice) | ||
{ | ||
case 1: | ||
insert(); | ||
break; | ||
case 2: | ||
delete(); | ||
break; | ||
case 3: | ||
display(); | ||
break; | ||
case 4: | ||
printf("EXIT"); | ||
} | ||
}while(choice!=4); | ||
} | ||
/* ""OUTPUT"" | ||
1.Insert element to queue | ||
2.Delete element from queue | ||
3.Display all elements of queue | ||
4.Quit | ||
Enter your choice : 1 | ||
Inset the element in queue : 10 | ||
Enter your choice : 1 | ||
Inset the element in queue : 20 | ||
Enter your choice : 1 | ||
Inset the element in queue : 30 | ||
Enter your choice : 3 | ||
Queue is : | ||
10 20 30 | ||
Enter your choice : 2 | ||
Element deleted from queue is : 10 | ||
Enter your choice : 2 | ||
Element deleted from queue is : 20 | ||
Enter your choice : 3 | ||
Queue is : | ||
30 | ||
Enter your choice : 4 | ||
EXIT | ||
*/ |
Oops, something went wrong.