Question

PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4:...

PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4: A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods: Method isPalindome() to check if a number is palindrome or not. Method isPrime() to check if a number is prime or not. In the main method, use a loop structure to invokes these methods and print out the palindromic primes. Document your code and properly format the outputs as shown below. Output format (each x is a palindromic prime number): x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Hint: Use modulus and division by 10 to reverse the number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
public class Program
{
   public static int[] prime_nos = new int[1000]; //Global array which holds prime numbers
   public static int[] pal_nos = new int[1000]; //Global array which holds palindrome numbers
   public static int compare_arry(int[] prime_array, int[] pal_nos, int c) //Function to compare each element in Prime and Palindrome array and return value if elements are same.
   {
       Console.Write("Palindromic Prime Numbers\n");
       for (int i = 0; i < c; i++)
       {
           if (prime_array[i] == pal_nos[i])
               Console.Write(" " + pal_nos[i]);
       }
       return 0;
   }

   public static int generate_Prime(int c)//Function to genreate the prime numbers upto c numbers here it is 50 as in Main
   {
       int k = 1;
       bool isPrime = true;
       for (int i = 2; i <= 10000; i++)//This loop generate prime numbers upto 100000
       {
           for (int j = 2; j <= 100000; j++)
           {
               if (i != j && i % j == 0)
               {
                   isPrime = false;
                   break;
               }
           }
           if (isPrime)
           {
               if (k > c) //check if the number of prime numbers generated is greater than n which is 50, if so stop generating prime
                   break;
               prime_nos[k - 1] = i; //else assign primne number to prim_nos array
               k++; //increament the prime number count by 1
           }
           isPrime = true;
       }
       return 0;
   }
   public static int isPalindrome(int[] prime_array, int c) //check if element from prime_array is palindrome or not
   {
       //for(int k=0;k<c;k++)
       // Console.Write(" "+prime_array[k]);
       int remainder, temp, reverse = 0, num;
       for (int i = 0; i < c; i++)
       {
           num = prime_array[i];
           temp = num;
           while (num > 0)
           {
               remainder = num % 10;
               reverse = reverse * 10 + remainder;
               num /= 10;
           }
           //Console.Write(" "+ reverse);
           pal_nos[i] = reverse;
           reverse = 0;
           temp = 0;
           remainder = 0;
       }
       compare_arry(prime_array, pal_nos, c); //compare prime_array and palindrom array which is pal_nos to putput palindromic prime
       return 0;
   }
   public static void Main(string[] args) //main program
   {
       int n = 50; //MAX 1000
       generate_Prime(n); //call prime number generation method
       isPalindrome(prime_nos, n); //call methos to check for palindrome and print the palindromic prime by calling compare_arry() internally.
   }
}

Output:

Palindromic Prime Numbers 2 3 57 11 101 131 151 181 191 .Program finished with exit code 0 Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Program 4:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING C# AND PSUDOCODE PLEASE : A palindromic prime number is a number that is both...

    USING C# AND PSUDOCODE PLEASE : A palindromic prime number is a number that is both prime number and a palindrome number. For example, 131, 313, and 757 are palindromic prime numbers. Design (pseudocode) and implement (source code) a program (name it PalindromicPrime) to display the first 50 palindromic prime numbers, 10 per line separated by one space. The program defines the following methods: Method isPalindome() to check if a number is palindrome or not. Method isPrime() to check if...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2: Design (pseudocode) and implement (source code) a class called Counter. It should have one private instance variable representing the value of the counter. It should have two instance methods: increment() which adds on to the counter value and getValue() which returns the current value. After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head...

  • No. 7 7th question i want this code to be done on c++ visual studio without...

    No. 7 7th question i want this code to be done on c++ visual studio without using bool operation. and please try to make as simple as possible. Also i need flowchart for the code thanks. Q7 I need a code programmed on c++ visual studios. Also flowchart of the code. Try to make it simple college level understandable code. thanks. b. wg. Prompt the user to input the value of a double variabler, which stores the radius of a...

  • A palindromic prime is a prime number that is also a palindrome (reads the same forwards...

    A palindromic prime is a prime number that is also a palindrome (reads the same forwards and backwards). For example, 373 is a palindromic prime. Write a Python program, in a file called palindromic_prime.py, to display the first n primes where the value of n is obtained from the user. Output NUM_PER_LINE palindromic primes per line, where NUM_PER_LINE is assigned to 10 (note format in sample output below). Your solution should include the following functions: isPrime(number) - returns True if...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns...

  • answer the following using C# Design and program a Visual Studio Console project in C# that...

    answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...

  • URGENT ! PLEASE DO IN C# AND MAKE SURE I CAN COPY COPY CODE INTO VISUAL...

    URGENT ! PLEASE DO IN C# AND MAKE SURE I CAN COPY COPY CODE INTO VISUAL STUDIO Define a method named SortArray() to sort a one dimensional array of integers. YOU MAY NOT CALL A BUILT-IN SORTING FUNCTION, but should write your own. The method should return the sorted array. You may use whichever sorting algorithm you prefer, in order to sort the array. Please initialize an array and fill it with random values before beginning. Ensure that it has...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT