Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Thursday, 18 April 2019

LCM of Two Number Program in C++

// LCM of two number is a*b divided by gcd/hcf of two number
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
int lcm=(a*b)/__gcd(a,b);
cout<<lcm;
}

Thursday, 15 November 2018

Longest Increasing Sub Sequences with Dynamic Programming in Python | C++ | C

# Author Mohd Mujtaba @ Play with C Plus
def LIS(l):
    n=len(l);
    l1=[1]*n;
    for i in range(n):
        for j in range(0,i):
            if(l[i]>l[j]):
                l1[i]=max(l1[j]+1,l1[i]);
    print(max(l1));
for _ in range(int(input())):
    n=int(input());
    l=list(map(int,input().split()));
    LIS(l);
   

Monday, 6 November 2017

Program to find K' th smallest number in Array In C,C++

#include<iostream>
using namespace std;

main()
{
int n,t,k;
cout<<"Enter No Of Testcases:";
cin>>t;
cout<<"Enter Number Of Elements:";
cin>>n
cout<<"Enter K'th Number To be finded:";
cin>>k;
int a[n],count=0,i,j,countb=0;
int b[n],p,q;
for(q=0;q<t;q++)
{
for(p=0;p<n;p++)
{
    cin>>a[p];
}

for(i=0;i<6;i++)
{
count=0;

int temp=a[i];
for(j=0;j<6;j++)
{
if(temp==a[j])
count++;

}
if(count==k)
{
b[i]=a[i];
countb++;
}
}
int small=b[0];
for(i=0;i<countb;i++)
{
if(small>b[i])
small=b[i];
}
cout<<"K'th Smallest Number Is:"<<small;

}

}


Amazon1Ads