Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views3 pages

Loop Program in C

The document contains multiple C programs that demonstrate basic programming concepts. It includes a program to reverse a number, check if a number is a palindrome, determine if a number is an Armstrong number, and print the Fibonacci series. Each program is structured with input prompts, logic for processing, and output statements.

Uploaded by

marutiroybabunu
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)
5 views3 pages

Loop Program in C

The document contains multiple C programs that demonstrate basic programming concepts. It includes a program to reverse a number, check if a number is a palindrome, determine if a number is an Armstrong number, and print the Fibonacci series. Each program is structured with input prompts, logic for processing, and output statements.

Uploaded by

marutiroybabunu
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/ 3

WAP to print reverse of a number in c

#include <stdio.h>

int main()

int num, rev = 0;

printf("Enter an Number ");

scanf("%d", &num);

while (num != 0) {

int digit = num % 10;

rev = rev * 10 + digit;

num = num / 10;

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

getch();

return 0;

WAP in C to check a Number is a Palindrome ot not a Palindrome.


#include <stdio.h>

int main() {
int num, original, rev = 0;

printf("Enter an integer: ");


scanf("%d", &num);

original = num;

while (num != 0)
{
int digit = num % 10;
rev = rev * 10 + digit;
num = num / 10;
}

if (original == rev)
{
printf("%d is a palindrome.\n", original);
}
Else
{
printf("%d is not a palindrome.\n", original);
}
getch();
return 0;
}

WAP in C to check a number is Armstrong number or not.


#include <stdio.h>
#include <math.h>

int main() {
int num, original, count = 0;
double sum = 0.0;

printf("Enter an integer: ");


scanf("%d", &num);

original = num;

while (num != 0)
{
count++;
num /= 10;
}

num = original;

while (num != 0)
{
int digit = num % 10;
sum += pow(digit, count);
num /= 10;
}

if ((int)sum == original) {
printf("%d is an Armstrong number.\n", original);
} else {
printf("%d is not an Armstrong number.\n", original);
}
getch();
return 0;
}

C program to print Fibonacci series:


#include <stdio.h>

int main() {
int n, i;
int t1 = 0, t2 = 1, nextTerm;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci Series: ");

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


if (i == 1) {
printf("%d ", t1);
continue;
}
if (i == 2) {
printf("%d ", t2);
continue;
}
nextTerm = t1 + t2;
printf("%d ", nextTerm);
t1 = t2;
t2 = nextTerm;
}

printf("\n");
getch();

return 0;
}

You might also like