


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



#include <stdio.h> int main() { int num, reversedNum = 0, originalNum; // Declare variables for the number, reversed number, and original number printf("Input a number: "); scanf("%d", &num); // Read the input number from the user originalNum = num; // Store the original number for comparison later // Start a while loop to reverse the digits of the number while (num != 0) { int remainder = num % 10; // Extract the last digit reversedNum = reversedNum * 10 + remainder; // Build the reversed number num /= 10; // Remove the last digit from the original number } // Check if the reversed number is equal to the original number if (originalNum == reversedNum) { printf("%d is a palindrome.\n", originalNum); } else { printf("%d is not a palindrome.\n", originalNum); } return 0; // Indicate successful program execution }
#include <stdio.h> int main() { int count = 10; // Number of Fibonacci numbers to generate int firstTerm = 0, secondTerm = 1; // Initialize the first two terms of the sequence
printf("First %d Fibonacci numbers:\n", count); // Start a while loop to generate Fibonacci numbers while (count > 0) { printf("%d, ", firstTerm); // Print the current Fibonacci number int nextTerm = firstTerm + secondTerm; // Calculate the next Fibonacci number firstTerm = secondTerm; // Update the first term with the value of the second term secondTerm = nextTerm; // Update the second term with the calculated next term count--; // Decrease the count for the next iteration } return 0; // Indicate successful program execution }
#include <stdio.h> int main() { int j, sum = 0; printf("The first 10 natural number is :\n"); for (j = 1; j <= 10; j++) { sum = sum + j; printf("%d ",j); } printf("\nThe Sum is : %d\n", sum); }
for (i = 1; i <= rows; i++) { // Start a loop to generate rows. for (j = 1; j <= i; j++) // Nested loop to print numbers based on the current row. printf("%d", j); // Print the value of 'j'. printf("\n"); // Move to the next line for the next row. } return 0; }