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

milestone 2 #37

Open
wants to merge 8 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
19 changes: 19 additions & 0 deletions HarpreetSinghNagi/Milestone 3/alphabet to ascii value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main()
{
int st=0, en=0, ascii;
cout<<"input the starting ASCII value : "<<st<<endl;
cin>>st;
cout<<"input the ending ASCII value : "<<en<<endl;
cin>>en;
if(st<=0 || st>=255)
st=0;
if(en<=0 || en>=255)
en=255;
for(ascii=st; ascii<=en; ascii++)
{
cout<<"ASCII value of "<<char(ascii)<<" : "<<ascii<<endl;
}
return 0;
}
19 changes: 19 additions & 0 deletions HarpreetSinghNagi/Milestone 3/first and last digit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main()
{
long int num=0,i=0 ,fd=0 , ld=0;
cout<<"enter a number : ";
cin>> num;
ld=num%10; //define ld before entering the loop.
while (num>10)
{
num=num/10;
i++;
fd=num;
}
cout<<"first digit of the number is : "<<fd<<endl;

cout<<"last digit of the number is : "<<ld;
return 0;
}
52 changes: 52 additions & 0 deletions HarpreetSinghNagi/Milestone 3/frequency of digits 2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
using namespace std;
int main()
{
long long int num, ld, ct=0, n=0, a;
cout<<"enter a number : "<<endl;
cin>>num;
a=num;
for(n=0; n<10; n++)
{ ct=0;
a=num;
while(a>0)
{
ld=a%10;
if (ld==n)
{
ct++;
}
a=a/10;
}
cout<<"frequency of "<<n<<" is : "<<ct<<endl;
ct=0;
}
}

/*
alternative :
#include <iostream>
using namespace std;
int main()
{
long long int num, n, ct, ld, m;
cout<<"enter a number : "<<endl;
cin>>num;
n=0;
while(n<10)
{
ct=0;
cout<<"the frequency of "<<n<<" is : ";
for(m=num; m>0; m=m/10)
{
ld=m%10;
if(ld==n)
{
ct++;
}
}
cout<<ct<<endl;
n++;
}
}
*/
23 changes: 23 additions & 0 deletions HarpreetSinghNagi/Milestone 3/frequency of digits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long long int num=0, ld=0,count=0, digit=0;
cout<<"enter a number : "<< num<<endl;
cin>> num;
cout<<"enter a digit : "<< digit<<endl;
cin>> digit;
while (num>0)
{
ld=num%10;
num=num/10;
if (ld==digit)
{
count++;
}
}
cout<<"frequency of "<<digit<<" is : "<<count;

return 0;
}
62 changes: 62 additions & 0 deletions HarpreetSinghNagi/Milestone 3/number in words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long long int num=0, ld=0, rev=0, ct=0, i, tz=0, extra=0;
cout<<"enter a number : "<<endl;
cin>> num;
while (num>0)
{
ld=num%10;
rev=rev*10+ld;
num=num/10;
if(ld==0)
{
ct++;
}
}
while(rev>0)
{
switch (rev%10)
{
case 0:
cout<<"zero ";
extra++; //for counting extra zeros.
break;
case 1:
cout<<"one ";
break;
case 2:
cout<<"two ";
break;
case 3:
cout<<"three ";
break;
case 4:
cout<<"four ";
break;
case 5:
cout<<"five ";
break;
case 6:
cout<<"six ";
break;
case 7:
cout<<"seven ";
break;
case 8:
cout<<"eight ";
break;
default:
cout<<"nine ";
}
rev=rev/10;
}
tz=ct-extra; //tz=trailing zeros
for(i=1; i<=tz; i++)
{
cout<<"zero "; //prints no. of trailing zeros.
}
return 0;
}
23 changes: 23 additions & 0 deletions HarpreetSinghNagi/Milestone 3/palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
#include<math.h>
using namespace std;
int main ()
{
long long int oldnum=0 ,num=0 ,ld=0, rev=0;
cout<<"enter a number : "<< oldnum<<endl;
cin>> oldnum;
num=oldnum;
while (num>0)
{
ld=num%10;
rev=rev*10+ld;
num=num/10;
}
cout<<"reverse : "<<rev<<endl;
if (rev==oldnum)
{
cout<<"it is a palindrome.";
}
else { cout<<"it is not a palindrome."; }
return 0;
}
18 changes: 18 additions & 0 deletions HarpreetSinghNagi/Milestone 3/product of digits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long long int num=0, ld, product;
cout<<"enter a number : "<< num<<endl;
cin>> num;
product=num%10;
while (num>10)
{
num=num/10;
ld=num%10;
product=product*ld;
}
cout<<"product of digits : "<<product<<endl;
return 0;
}
17 changes: 17 additions & 0 deletions HarpreetSinghNagi/Milestone 3/reverse of a number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long long int num=0, ld=0, rev=0;
cout<<"enter a number : "<< num<<endl;
cin>> num;
while (num>0)
{
ld=num%10;
rev=rev*10+ld;
num=num/10;
}
cout<<"reverse : "<<rev<<endl;
return 0;
}
18 changes: 18 additions & 0 deletions HarpreetSinghNagi/Milestone 3/sum of digits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long long int num=0, ld=0, sum=0;
cout<<"enter a number : "<<endl;
cin>> num;
sum=num%10;
while (num>0)
{
num=num/10;
ld=num%10;
sum=sum+ld;
}
cout<<"sum of digits : "<<sum<<endl;
return 0;
}
20 changes: 20 additions & 0 deletions HarpreetSinghNagi/Milestone 3/sum of ld and fd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main()
{
long long int num=0,i=0 ,fd=0 , ld=0, sum=0;
cout<<"enter a number : "<< num;
cin>> num;
ld=num%10; //define ld before entering the loop.
while (num>10)
{
num=num/10;
i++;
fd=num;
}
cout<<"first digit of the number is : "<<fd<<endl;
cout<<"last digit of the number is : "<<ld<<endl;
sum=ld+fd;
cout<<"sum of first and last digit is : "<<sum;
return 0;
}
22 changes: 22 additions & 0 deletions HarpreetSinghNagi/Milestone 3/swap ld and fd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long int num=1,i=0 ,fd=0 , ld=0, newnum=0, oldnum=0;
cout<<"enter a number : "<< oldnum;
cin>> oldnum;
num=oldnum;
ld=num%10; //define ld before entering the loop.
while (num>10)
{
num=num/10;
i++; //i=count
fd=num;
}
cout<<"first digit of the number is : "<<fd<<endl;
cout<<"last digit of the number is : "<<ld<<endl;
newnum=(ld*pow(10,i) +fd) + (oldnum-fd*pow(10,i)-ld) ; //pow(10,i) implies 10^i
cout<<oldnum<<" is swapped to "<<newnum;
return 0;
}
22 changes: 22 additions & 0 deletions HarpreetSinghNagi/Milestone 4/HCF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int num1=0, num2=0, i, min, hcf;
cout<<"enter a 1st number : "<<num1<<endl;
cin>>num1;
cout<<"enter a 2nd number : "<<num2<<endl;
cin>>num2;
min=(num1>num2) ? num2 : num1;
cout<<" HCF of "<< num1<<" and "<< num2<<" is : ";
for(i=1; i<=min; i++)
{
if(num1%i==0 && num2%i==0)
{
hcf=i;
}
}
cout<<hcf;
return 0;
}
35 changes: 35 additions & 0 deletions HarpreetSinghNagi/Milestone 4/LCM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
int num1=0, num2=0, a, b, mx, lcm=1, p, q;
cout<<"enter a 1st number : "<<endl;
cin>>num1;
cout<<"enter a 2nd number : "<<endl;
cin>>num2;
mx=(num1>num2) ? num1 : num2;
cout<<" LCM of "<< num1<<" and "<< num2<<" is : ";
for(a=1; a<=mx; a++)
{

p=num1*a;
for (b=1; b<=mx; b++)
{

q=num2*b;
if(p==q)
{
lcm=p;
break;
}
}
if (p==q)
{break;}
}
cout<<lcm;
return 0;
}
/*
* ALTERNATIVE : LCM=(num1*num2)/HCF
*/
16 changes: 16 additions & 0 deletions HarpreetSinghNagi/Milestone 4/factorial of a number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int num=0, i=1, factorial=1;
cout<<"enter a number : "<<endl;
cin>>num;
cout<<" --> "<<num<<"! = ";
for(i=1; i<=num; i++)
{
factorial*=i;
}
cout<<factorial;
return 0;
}
18 changes: 18 additions & 0 deletions HarpreetSinghNagi/Milestone 4/factors of a number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int num=0, i;
cout<<"enter a number : "<<endl;
cin>>num;
cout<<" factors of "<<num<<" are : ";
for(i=1; i<=num; i++)
{
if(num%i==0)
{
cout<<i<<", ";
}
}
return 0;
}
Loading