0% found this document useful (0 votes)
39 views4 pages

Using Namespace Int Int Int Int For For If Return: #Include N A

The document contains code snippets for several C++ functions: 1. The cdif() function checks if an integer array contains duplicate elements and returns 0 if so, 1 otherwise. 2. The inv() function reverses the digits of a number and returns the result. 3. The ncifpatrate() function checks if a number is a perfect square with the last digit as the given number, returning the perfect square if so. 4. Additional code snippets define functions for checking if a number is divisible by 2, 3, 5, 7 or 9, summing digits of numbers in an array if they meet certain criteria, and counting divisors or prime divisors of numbers between given bounds.

Uploaded by

Gherasie Gabriel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Using Namespace Int Int Int Int For For If Return: #Include N A

The document contains code snippets for several C++ functions: 1. The cdif() function checks if an integer array contains duplicate elements and returns 0 if so, 1 otherwise. 2. The inv() function reverses the digits of a number and returns the result. 3. The ncifpatrate() function checks if a number is a perfect square with the last digit as the given number, returning the perfect square if so. 4. Additional code snippets define functions for checking if a number is divisible by 2, 3, 5, 7 or 9, summing digits of numbers in an array if they meet certain criteria, and counting divisors or prime divisors of numbers between given bounds.

Uploaded by

Gherasie Gabriel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

#include <iostream>
using namespace std;
int cdif(int n, int a[])
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[j] == a[i])
return 0;
}
}
return 1;
}
int main()
{
int i, n, a[10001];
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
{
if (a[i] < 500 && a[i]>1000 && cdif() == 1)
cout << a[i];
}
}

2. #include <iostream>
using namespace std;
int b[1001];
int inv(int n, int a[])
{
int i, j;
for (i = 0; i < n; i++)
{
b[i] = 0;
while (a[i])
{
j = a[i] % 10;
b[j] = b[j] * 10 + a[i];
n = n / 10;
}
return b[i];

}
int main()
{
int i, n, a[10001];
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
{
cout << inv(b[i]);
}
}
3. #include <iostream>
using namespace std;
int b[1001];
int ncifpatrate(int n)
{
int i, c,patrat;
if (n == 2 && n == 3 && n == 7 && n == 8)
return 0;
else
{
for (i = 1; i <= 1000; i++)
{
patrat = i * i;
if (patrat % 10 == n)
return patrat;

}
}
}
5. #include <iostream>
using namespace std;
int b[1001];
int par(int cif)
{
if (cif == 1 && cif == 3 && cif == 5 && cif == 7 && cif == 9)
return 0;
else return 1;

int sumcif{int n , int a[])


{
int S = 0,cif,OK;
for (i = 0; i < n; i++)
{
OK = 1;
while (a[i])
{
cif = n % 10;
if (par(cif) == 0)
OK = 0;
}
if (OK == 1)
S = S + a[i];
}
if (S == 0)
return"Nu exista numere cu toate cifrele pare"
else
return S;
}
6.
#include <iostream>
using namespace std;
int sumproddiv(int n)
{
int d ,S=0,P=1;

for (d = 2; d*d <= n; d++)


{
if (n % d == 0)
S = S + d;
P = P * d;
}
}
return S;
return P;
}
7.
#include <iostream>
using namespace std;
int sumproddiv(int n,int a,int b)
{
int S=0,ctrl=0,P=0,d;

for (d = 2; d*d <= n; d++)


{
if (n % d == 0)
{
S = S + d;
if (d > a && d < b)
{
ctrl++;
P = P + d;
}
}
}
if (ctrl > 0)
{
P = P / ctrl;
return P;
}
else
return"Nu exista divizori intre a si b";
return S;
}
8.
#include <iostream>
using namespace std;
int sumproddiv(int n, int a, int b)
{
int ctrl = 0, d, i, OK=1;

for (d = 2; d * d <= n; d++)


{
if (n % d == 0)
{
for (i = 2; i * i <= d; i++)
{
if (d % i == 0)
OK = 0;
}
if(OK==1)
ctrl++:
}
}
return ctrl;
}

You might also like