0% found this document useful (0 votes)
20 views11 pages

Assign2 Finupload

Uploaded by

nlakshaya2005
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)
20 views11 pages

Assign2 Finupload

Uploaded by

nlakshaya2005
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/ 11

#include <stdio.

h>

#include <stdbool.h>

// Function to check if a number is prime

bool isPrime(int num) {

if (num <= 1) {

return false;

for (int i = 2; i * i <= num; i++) {

if (num % i == 0) {

return false;

return true;

// Function to count the number of zeros in a number

int countZeros(int num) {

int count = 0;

while (num > 0) {

if (num % 10 == 0) {

count++;

num /= 10;

return count;

// Function to reverse a number

int reverseNumber(int num) {

int reversed = 0;
while (num > 0) {

reversed = reversed * 10 + (num % 10);

num /= 10;

return reversed;

// Function to check if digits are in ascending order

bool digitsInAscendingOrder(int num) {

int lastDigit = num % 10;

num /= 10;

while (num > 0) {

int currentDigit = num % 10;

if (currentDigit >= lastDigit) {

return false;

lastDigit = currentDigit;

num /= 10;

return true;

// Function to count the number of digits in a number

int countDigits(int num) {

int count = 0;

while (num > 0) {

num /= 10;

count++;

return count;

}
// Function to count total number of single digit odd numbers

int countSingleDigitOddPrimes() {

int count = 0;

for (int i = 3; i <= 9; i += 2) {

if (isPrime(i)) {

count++;

return count;

// Function to count total number of two digit odd numbers

int countTwoDigitOddNumbers() {

int count = 0;

for (int i = 11; i <= 99; i += 2) {

if (isPrime(i)) {

count++;

return count;

// Function to count total number of three digit odd numbers

int countThreeDigitOddNumbers() {

int count = 0;

for (int i = 101; i <= 999; i += 2) {

if (isPrime(i)) {

count++;

}
return count;

// Function to calculate the sum of single digit odd numbers

int sumOfSingleDigitOddPrimes() {

int sum = 0;

for (int i = 3; i <= 9; i += 2) {

if (isPrime(i)) {

sum += i;

return sum;

// Function to calculate the sum of two digit odd numbers

int sumOfTwoDigitOddNumbers() {

int sum = 0;

for (int i = 11; i <= 99; i += 2) {

if (isPrime(i)) {

sum += i;

return sum;

// Function to calculate the sum of three digit odd numbers

int sumOfThreeDigitOddNumbers() {

int sum = 0;

for (int i = 101; i <= 999; i += 2) {

if (isPrime(i)) {

sum += i;
}

return sum;

// Function to find the smallest prime number with n digits

int findSmallestPrimeWithNDigits(int n) {

int lowerBound = 1;

for (int i = 1; i < n; i++) {

lowerBound *= 10;

int upperBound = lowerBound * 10 - 1;

for (int num = lowerBound; num <= upperBound; num++) {

if (isPrime(num)) {

return num;

return -1; // No prime found within the range

// Function to find the largest prime number with n digits

int findLargestPrimeWithNDigits(int n) {

int lowerBound = 1;

for (int i = 1; i < n; i++) {

lowerBound *= 10;

int upperBound = lowerBound * 10 - 1;

for (int num = upperBound; num >= lowerBound; num--) {

if (isPrime(num)) {

return num;

}
}

return -1; // No prime found within the range

// Function to count the number of zeroes from 0 to num

int countZerosUpTo(int num) {

int count = 0;

for (int i = 0; i <= num; i++) {

count += countZeros(i);

return count;

// Function to count non-decreasing numbers in a range

int countNonDecreasingNumbers(int start, int end) {

int count = 0;

for (int num = start; num <= end; num++) {

if (digitsInAscendingOrder(num)) {

count++;

return count;

// Function to count palindrome numbers less than a limit

int countPalindromesUpTo(int limit) {

int count = 0;

for (int num = 1; num < limit; num++) {

int reversed = reverseNumber(num);

if (num == reversed) {

count++;
}

return count;

int main() {

int choice;

// Prompt the user for the desired question number

printf("Enter the question number (80-106) to perform the corresponding operation: ");

scanf("%d", &choice);

switch (choice) {

case 80: {

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("%s\n", isPrime(num) ? "Number is Prime" : "Number is not Prime");

break;

case 81: {

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("%d\n", countZeros(num));

break;

case 82: {

int num;

printf("Enter a number: ");

scanf("%d", &num);
printf("%d\n", reverseNumber(num));

break;

case 83: {

int num1, num2;

printf("Enter two numbers separated by a comma: ");

scanf("%d,%d", &num1, &num2);

printf("%s\n", num1 == num2 ? "Same" : "Not Same");

break;

case 84: {

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("%s\n", digitsInAscendingOrder(num) ? "Yes" : "No");

break;

case 85: {

int num;

printf("Enter a two-digit number: ");

scanf("%d", &num);

int reversed = (num % 10) * 10 + (num / 10);

printf("%d\n", reversed);

break;

case 86: {

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("%d\n", countDigits(num));

break;
}

case 87: {

printf("%d\n", countSingleDigitOddPrimes());

break;

case 88: {

printf("%d\n", countTwoDigitOddNumbers());

break;

case 89: {

printf("%d\n", countThreeDigitOddNumbers());

break;

case 90: {

printf("%d\n", sumOfSingleDigitOddPrimes());

break;

case 91: {

printf("%d\n", sumOfTwoDigitOddNumbers());

break;

case 92: {

printf("%d\n", sumOfThreeDigitOddNumbers());

break;

case 93: {

printf("%d\n", countSingleDigitOddPrimes());

break;

case 94: {

printf("%d\n", countTwoDigitOddNumbers());
break;

case 95: {

printf("%d\n", countThreeDigitOddNumbers());

break;

case 96: {

printf("%d\n", sumOfSingleDigitOddPrimes());

break;

case 97: {

printf("%d\n", sumOfTwoDigitOddNumbers());

break;

case 98: {

printf("%d\n", sumOfThreeDigitOddNumbers());

break;

case 99: {

printf("%d\n", findSmallestPrimeWithNDigits(3));

break;

case 100: {

printf("%d\n", findLargestPrimeWithNDigits(3));

break;

case 101: {

printf("%d\n", findSmallestPrimeWithNDigits(4));

break;

case 102: {
printf("%d\n", findLargestPrimeWithNDigits(4));

break;

case 103: {

printf("%d\n", findLargestPrimeWithNDigits(8));

break;

case 104: {

printf("%d\n", countZerosUpTo(1000));

break;

case 105: {

printf("%d\n", countNonDecreasingNumbers(1000, 9999));

break;

case 106: {

printf("%d\n", countPalindromesUpTo(100000));

break;

default:

printf("Invalid choice. Please choose a valid question number.\n");

break;

return 0;

You might also like