Merge pull request #20 from shivhek25/master

Added buzz number program.
This commit is contained in:
Anup Kumar Panwar
2017-06-07 14:49:38 +05:30
committed by GitHub
5 changed files with 106 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

17
Buzz_number.cpp Normal file
View File

@@ -0,0 +1,17 @@
//A buzz number is a number that is either divisble by 7 or has last digit as 7.
#include <iostream>
using namespace std;
int main()
{
int n,t;
cin >> t;
while(t--)
{
cin >> n;
if((n%7==0)||(n%10==7))
cout << n << " is a buzz number" << endl;
else
cout << n << " is not a buzz number" << endl;
}
return 0;
}

26
Happy_number.cpp Normal file
View File

@@ -0,0 +1,26 @@
/* A happy number is a number whose sum of digits is calculated until the sum is a single digit,
and this sum turns out to be 1 */
#include <iostream>
using namespace std;
int main()
{
int n,k,s=0,d;
cout << "Enter a number:";
cin >> n;
s=n;k=n;
while(k>9)
{
while(k!=0)
{
d=n%10;
s+=d;
n/=10;
}
k=s;
s=0;
}
if(k==1)
cout << n << " is a happy number" << endl;
else
cout << n << " is not a happy number" << endl;
}

View File

@@ -0,0 +1,30 @@
#include <iostream>
int main()
{
int i,j,m,n;
cout <<"Enter size of array 1:";
cin >> m;
cout <<"Enter size of array 2:";
cin >> n;
int a[m];
int b[n];
cout <<"Enter elements of array 1:";
for(i=0;i<m;i++)
cin >> a[i];
for(i=0;i<n;i++)
cin >> b[i];
i=0;j=0;
while((i<m)&&(j<n))
{
if(a[i]<b[j])
i++;
else if(a[i]>b[j])
j++;
else
{
cout << a[i++]<<" ";
j++;
}
}
return 0;
}

33
Union_of_2_arrays.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <iostream>
int main()
{
int m,n,i=0,j=0;
cout << "Enter size of both arrays:";
cin >> m >> n;
int a[m];
int b[n];
cout << "Enter elements of array 1:";
for(i=0;i<m;i++)
cin >>a[i];
cout << "Enter elements of array 2:";
for(i=0;i<n;i++)
cin >> b[i];
i=0;j=0;
while((i<m)&&(j<n))
{
if(a[i]<b[j])
cout << a[i++] <<" ";
else if(a[i]>b[j])
cout << b[j++] <<" ";
else
{
cout << a[i++];
j++;
}
}
while(i<m)
cout<< a[i++] <<" ";
while(j<n)
cout<< b[j++]<<" ";
return 0;
}