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

Eva

Uploaded by

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

Eva

Uploaded by

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

1

• #include <stdio.h>

• // Function to check if a number is perfect


• int isPerfect(int num) {
• int sum = 0;

• // Find divisors and add them


• for (int i = 1; i <= num / 2; i++) {
• if (num % i == 0) {
• sum += i;
• }
• }

• // Return 1 if number is perfect, else 0


• return (sum == num);
• }

• int main() {
• int number;

• // Input from the user


• printf("Enter a number: ");
• scanf("%d", &number);

• // Check if the number is perfect


• if (isPerfect(number)) {
• printf("%d is a perfect number.\n", number);
• } else {
• printf("%d is not a perfect number.\n", number);
• }

• return 0;
• }
2
#include <stdio.h>

// Function to calculate factorial of a digit


int factorial(int digit) {
int fact = 1;
for (int i = 1; i <= digit; i++) {
fact *= i;
}
return fact;
}

int main() {
int num, originalNum, remainder, sum = 0;

// Input from the user


printf("Enter a number: ");
scanf("%d", &num);

originalNum = num;

// Loop to calculate the sum of the factorial of each digit


while (num > 0) {
remainder = num % 10; // Get the last digit
sum += factorial(remainder); // Add factorial of the digit
num /= 10; // Remove the last digit
}

// Check if the sum of factorials is equal to the original number


if (sum == originalNum) {
printf("%d is a strong number.\n", originalNum);
} else {
printf("%d is not a strong number.\n", originalNum);
}

return 0;
}
3
• #include <stdio.h>

• // Recursive function to return nth Fibonacci number


• int fibonacci(int n) {
• if (n == 0) {
• return 0;
• } else if (n == 1) {
• return 1;
• } else {
• return fibonacci(n - 1) + fibonacci(n - 2);
• }
• }

• int main() {
• int limit, i = 0, fib;

• // Input from the user


• printf("Enter the number up to which Fibonacci sequence should be printed: ");
• scanf("%d", &limit);

• printf("Fibonacci Sequence: \n");

• // Generate Fibonacci sequence until the number exceeds the user limit
• while (1) {
• fib = fibonacci(i);
• if (fib > limit) {
• break;
• }
• printf("%d ", fib);
• i++;
• }

• return 0;
• }
4
• #include <stdio.h>

• // Recursive function to reverse the number


• int reverseNumber(int num, int rev) {
• if (num == 0) {
• return rev;
• } else {
• rev = rev * 10 + (num % 10); // Add the last digit to rev
• return reverseNumber(num / 10, rev); // Recursion with the remaining digits
• }
• }

• int main() {
• int num, reversedNum;

• // Input from the user


• printf("Enter a number: ");
• scanf("%d", &num);

• // Call the recursive function to reverse the number


• reversedNum = reverseNumber(num, 0);

• printf("Reversed number: %d\n", reversedNum);

• return 0;
• }

You might also like