Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-kumar99 authored Oct 20, 2020
2 parents a279cec + d0f4dd4 commit 27e405e
Show file tree
Hide file tree
Showing 43 changed files with 1,595 additions and 355 deletions.
50 changes: 25 additions & 25 deletions C/HarshadNumber.cpp
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;
}
63 changes: 63 additions & 0 deletions C/Permutation of string in C
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
include<stdio.h>

#include<string.h>

void permutation(char *,int,int);

int main()

{

//int j,i;

char s[30];

//int n=strlen(s);

printf("Enter the string :");

gets(s);

permutation(s,0,strlen(s));

return 0;

}

void permutation(char *s,const int start,int end)

{

int i,j;

char temp;

for(i=start;i<end-1;i++){

for(j=i+1;j<end;j++){

// printf("%c",s[j]);

temp=s[i];

s[i]=s[j];

s[j]=temp;

permutation(s,i+1,end);

temp=s[i];

s[i]=s[j];

s[j]=temp;

}

}

printf("%s\n",s);

}


37 changes: 0 additions & 37 deletions C/is binary number a multiple of 3?

This file was deleted.

64 changes: 32 additions & 32 deletions C/knapsack.cpp
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;
}
Loading

0 comments on commit 27e405e

Please sign in to comment.