SCRIEȚI UN PROGRAM C++ CARE SA ARETE :
/scrieti toate numerele mai mici decât B
//și mai mari decât A(din intervalul AB) unde A și B se dau
de către utilizator
//in ordine descrescătoare
IMI TREBUIE URGENTTTT...DAU 50PUNCTEEEEE
Răspunsuri la întrebare
Răspuns:
// A C++ program for finding numbers which are
// decimal as well as binary palindrome
#include <iostream>
using namespace std;
// A utility to check if number is palindrome on base b
bool IsPalindrome(int number, int b)
{
int reversed = 0;
int k = number;
// calculate reverse of number
while (k > 0) {
reversed = b * reversed + k % b;
k /= b;
}
// return true/false depending upon number is palindrome or not
return (number == reversed);
}
// A utility for creating palindrome
int createPalindrome(int input, int b, bool isOdd)
{
int n = input;
int palin = input;
// checks if number of digits is odd or even
// if odd then neglect the last digit of input in finding reverse
// as in case of odd number of digits middle element occur once
if (isOdd)
n /= b;
// creates palindrome by just appending reverse of number to itself
while (n > 0) {
palin = palin * b + (n % b);
n /= b;
}
return palin;
}
// Function to print decimal and binary palindromic number
void findPalindromic(int n)
{
int number;
for (int j = 0; j < 2; j++) {
bool isOdd = (j % 2 == 0);
// Creates palindrome of base 10 upto n
// j always decides digits of created palindrome
int i = 1;
while ((number = createPalindrome(i, 10, isOdd)) < n) {
// if created palindrome of base 10 is
// binary palindrome
if (IsPalindrome(number, 2))
cout << number << " ";
i++;
}
}
}
// Driver Program to test above function
int main()
{
int n = 1000;
findPalindromic(n);
return 0;
}
sper sa fie ok , daca nu te mai uiti tu la bug-uri
Succes