0% found this document useful (0 votes)
2 views5 pages

C Programs for Number Series and Checks

The document contains multiple C programs that demonstrate basic algorithms: generating the Fibonacci series, reversing a number, checking for palindromes, determining if a number is prime, and verifying Armstrong numbers. Each program prompts the user for input and performs calculations based on the provided number. The code snippets illustrate fundamental programming concepts and control structures in C.

Uploaded by

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

C Programs for Number Series and Checks

The document contains multiple C programs that demonstrate basic algorithms: generating the Fibonacci series, reversing a number, checking for palindromes, determining if a number is prime, and verifying Armstrong numbers. Each program prompts the user for input and performs calculations based on the provided number. The code snippets illustrate fundamental programming concepts and control structures in C.

Uploaded by

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

Fibonacci Series

#include <stdio.h>

int main() {

int a=0,b=1,c,n,i;

printf("Enter a number of term of fibonacci series : ");

scanf("%d", &n);

printf("%d ",a);

printf("%d ",b);

for(i=2;i<n;i++)

c=a+b;

printf("%d ",c);

a=b;

b=c;

}
Reverse

#include <stdio.h>

int main() {

int num, reversedNum = 0, remainder;

printf("Enter a number: ");

scanf("%d", &num);

// Extract digits and reverse the number

while (num != 0) {

remainder = num % 10;

reversedNum = reversedNum * 10 + remainder;

num /= 10;

printf("%d Reverse of given number is", reversedNum);

return 0;

}
Palindrome

#include <stdio.h>

int main() {

int num, originalNum, reversedNum = 0, remainder;

printf("Enter a number: ");

scanf("%d", &num);

originalNum = num; // Save the original number

// Extract digits and reverse the number

while (num != 0) {

remainder = num % 10;

reversedNum = reversedNum * 10 + remainder;

num /= 10;

// Check if the original number is equal to the reversed number

if (originalNum == reversedNum)

printf("%d is a palindrome.\n", originalNum);

else

printf("%d is not a palindrome.\n", originalNum);

return 0;

}
Prime

#include <stdio.h>

int main() {

int num,i, factorCount = 0;

printf("Enter a number: ");

scanf("%d", &num);

// Count the factors of the given number

for ( i = 1; i <= num; i++) {

if (num % i == 0)

factorCount++;

// Check if the number is prime (has exactly 2 factors)

if (factorCount == 2)

printf("%d is a prime number.\n", num);

else

printf("%d is not a prime number.\n", num);

return 0;

}
Armstrong

#include <stdio.h>

#include <math.h>

int main() {

int num, originalNum, remainder, n = 0, sum = 0;

printf("Enter a number: ");

scanf("%d", &num);

originalNum = num; // Save the original number

// Calculate the number of digits

while (originalNum != 0) {

originalNum /= 10;

++n;

originalNum = num; // Reset originalNum to the initial value

// Calculate the sum of cubes of digits

while (originalNum != 0) {

remainder = originalNum % 10;

sum += pow(remainder, n);

originalNum /= 10;

// Check if it is an Armstrong number

if (sum == num)

printf("%d is an Armstrong number.\n", num);

else

printf("%d is not an Armstrong number.\n", num);

return 0;

You might also like