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

Generic Code Solutions for Number Programs

The document outlines a series of programming tasks that require the implementation of various algorithms using both loops and goto statements. Each task focuses on manipulating numbers, checking properties like odd/even, prime status, and performing bitwise operations. The examples provided illustrate the expected input and output for each programming challenge.

Uploaded by

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

Generic Code Solutions for Number Programs

The document outlines a series of programming tasks that require the implementation of various algorithms using both loops and goto statements. Each task focuses on manipulating numbers, checking properties like odd/even, prime status, and performing bitwise operations. The examples provided illustrate the expected input and output for each programming challenge.

Uploaded by

koteswari1529
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Note Write generic code such that it should work for any given input.

------------------------------------------------------------------------------------------------------------------
1]
Write a program to print binary of each digit in a given number using goto.
Don’t use any loop.
Hint: Use nested goto.
Input: Num=1234;
Output:
00000100
00000011
00000010
00000001

2]
Write a program to check first digit of any given number whether it is odd or even.
Note: Don’t reverse the number.
Example: Input int num=1234;
Check 1 is even or not.
Do using both For loop and goto

3]
Write a program to count how many set bits are there in a byte. If the set bit count is even clear the
first nibble in each byte.
Do using both For loop and goto.
Example:
Input binary: 00010101 01100011 11100000 10101111
Output : 00010101 01100000 11100000 10100000

4]
Write a program to delete the largest digit in a given number.
Input: int num=12521
Ouput num=1221
Do using both For loop and goto.

5]
Write a program to delete the first digit from right side which contain prime set bit count.
Example:
Input int num=1234
Output num=124
Here digit3 contain prime set bit count.

6]
Write a program to swap nibbles in each byte of a given integer number.
Example:
Input binary: 10100011 00111100 10101111 00001111
Output binaty:00111010 11000011 11111010 11110000

7]
Write a program to print Nth prime number from given number num
Take N and num from user.
Example: If N is 3 and num is 10.
So print 3rd prime number from 10
Output: 17

8]
Write a program to replace middle digit of any given number by the count of set bit in that digit.
Example: int num=12345;
In 3 there are 2 set bit.
Output : num=12245

int num=1234;
So middle digit is n/2 +1 where n is number of digits in a given number.

9]
Implement two’s complement of any given number using Bitwise Operator. Don’t use complement
operator(~).
Example Input int num=2 00000000 00000000 00000000 00000010
Output num=-3 11111111 11111111 11111111 11111110
Use xor operator

10]
Set all the bits after the leftmost set bit
Example Input int num=30 00000000 00000000 00000000 00011110
Here 4th bit is the leftmost setbit So set all the bit after 4th bit
Output 11111111 11111111 11111111 11111110
Don’t disturb right most part
Example Input int num=32 00000000 00000000 00000000 00100000
Output 11111111 11111111 11111111 11100000
Try this using Goto and For loop

11]
Check whether a binary representation of a given number is palindrome or not using bitwise
operators.
Example int num=0x1800 00000000 00000001 10000000 00000000
This binary representation is Palindrome

12]
Write a program to add first digit of all non armstrong number in range 2000 to 2 such that there
first digit is odd.
For example from 2000 side first number is 2000 but its first digit is not odd, 1999 is not armstrong
and one is odd so add that and in such manner print sum of all such digit.

13]
Write a program to add all the palindrome in range upto given palindrome.
Take range from user. Asume that range is 1000 to 100
Take one palindrome number as a input in a given range. Suppose it is 555

14]
Write a program to print number in range 1000 to 2 such that the number is palindrome and if it is
palindrome check whether it is prime or not. If the number is palindrome and prime both then only
print such number
15]
Write a program to print such a number in range 2 to 3000 which are prime and at the same time
there digit also prime.
For example 2,3,5,7,23,37 etc

16]
Write a program to print such a pair of prime number in range 3 to 1000 which are differ by 2
Output-
3,5
5,7
11,13
17,19

17]
Wrte a progrm to print how many palindrome number is required such that the sum of all these
palindrome can pass over given sum.
Take sum from user
Range given 10 to 1500
Suppose sum taken from user and it is 150.
So print the count of palindrome number which is required so that sum of such palindrome will pass
the given sum which is 150.

18]
In a given range print such palindrome whose sum of digit is prime.
Take range from user.
For example num=212 this is palindrome and sum of digit is 5 which is prime print such number
in a given range.
Note: Use while loop

19]
Write a program to count such number in a given range whose digit sum is prime and that sum
contain even set bit count.
Take range from user.
Note: Use do while loop

20]
Write a program to count such palindrome number in a given range which are prime too.
Take range from user.
Note: Use do while loop

21]
Write a program to extract middle digit of any given number and if that digit is prime so add the
middle digit at second position of a given number. If the middle digit is not prime then place that
digit at the second last position of the given number.
Example int num=12456;
Middle digit is 4 which is not a prime then output is
12546

int num=12356;
Middle digit is 3 which is a prime then output is
13256.
Note: Use while loop
22]
Write a program to replace each prime digit by it’s next fifth prime digit.
If the next fifth prime digit is two digit so add it’s digit until we did not get signle digit.
Then replace prime digit in a given number by single digit sum.
Example:
int num=38
Now 3 is prime digit. So fifth prime digit from 3 is 17.
Sum of digit in 17 is 8
So Output is 88

int num=975
Now 5 is prime digit. So fifth prime digit from 5 is 19.
Sum of digit in 19 is 10.
Take again sum until that sum not become single digit. So now sum is 1
So 5 is replaced by 1.
Also 7 is prime digit. So fifth prime digit from 7 is 23.
Sum of digit in 23 is 5.
So now sum is 1
So 7 is replaced by 1.
Output: 911

You might also like