0% found this document useful (0 votes)
54 views

1.armstrong Checking: #Include Int Int

1. The first document contains three C++ programs: one to check if a number is an Armstrong number, one to check if a number is prime, and one to generate all prime numbers within a range of lower and upper limits provided by the user. 2. The second document contains a C program to insert a given integer into a sorted array in the correct position to maintain the sorted order and return the updated size of the array. It takes the array, current size, and element to insert as parameters. 3. The third document contains four C/C++ programs to perform different tasks related to number checking and array operations.

Uploaded by

ankush ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

1.armstrong Checking: #Include Int Int

1. The first document contains three C++ programs: one to check if a number is an Armstrong number, one to check if a number is prime, and one to generate all prime numbers within a range of lower and upper limits provided by the user. 2. The second document contains a C program to insert a given integer into a sorted array in the correct position to maintain the sorted order and return the updated size of the array. It takes the array, current size, and element to insert as parameters. 3. The third document contains four C/C++ programs to perform different tasks related to number checking and array operations.

Uploaded by

ankush ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Armstrong Checking

#include<stdio.h>

int main()
{
int n,sum=0;
printf("Enter a number\t");
scanf("%d",&n);
int b=n;
while(n!=0)
{
int r=n%10;
sum+=r*r*r;
n/=10;
}
if(b==sum)
printf("\nArmstrong\n");
else
printf("\nNot Armstrong\n");
return 0;
}

2. Prime Checking

#include<iostream>
using namespace std;

class prime
{
private:
int n;
public:
void read_number();
void check();
};

void prime::read_number()
{
cout<<"Enter a number:\t";
cin>>n;
}

void prime::check()
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
cout<<"\n"<<n<<" is Prime number\t";
else
cout<<"\n"<<n<<" is not a prime number\n";
}

int main()
{
prime obj;
obj.read_number();
obj.check();
return 0;
}

3.Prime number Generating in a range.


#include<iostream>
using namespace std;

class prime
{
private:
int lower_limit,upper_limit;
public:
void read_limits();
void check();
};

void prime::read_limits()
{
cout<<"Enter the lower limit and upper limit\n";
cin>>lower_limit>>upper_limit;
}

void prime::check()
{
cout<<"\nThe prime numbers between :"<<lower_limit<<": and:"
<<upper_limit<<":are\n.................................";
cout<<"\n................................................\n";
for(int n=lower_limit;n<=upper_limit;n++)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
cout<<n<<"\t";
}
cout<<"\n..................................................";
cout<<"\n..................................................";
}

int main()
{
prime obj;
obj.read_limits();
obj.check();
return 0;
}

4. Insert a number in an array that is already sorted in ascending order


#include<stdio.h>
#include<stdlib.h>
int insert(int *,int ,int);
void display(int *,int );
int main()
{
int *a, n, ele;
printf("Enter the size of the array:\t");
scanf("%d",&n);
a=(int *)malloc(n*sizeof(int));
printf("Enter the elements one by one:\n");
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nEnter the element which you want to insert:\t");
scanf("%d",&ele);
int p=insert(a,n,ele);
display(a,p);
return 0;
}
int insert(int *a,int n,int ele)
{
for(int i=0;i<n;i++)
{
if(a[i]>ele)
{
for(int j=n-1;j>=i;j--)
{
a[j+1]=a[j];
}
a[i]=ele;
break;
}
}
n++;
return n;
}
void display(int *a,int n)
{
for(int i=0;i<n;i++)
printf("%d\t",a[i]);
}

You might also like