0% found this document useful (0 votes)
12 views2 pages

Reversing A Number Using While Loop

The document contains code snippets for three C programs: 1) A program that reverses an integer using a while loop. 2) A program that finds the largest of three input numbers. 3) A program that prints the Fibonacci series up to a given number of terms using a for loop.

Uploaded by

mrajislm5374
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)
12 views2 pages

Reversing A Number Using While Loop

The document contains code snippets for three C programs: 1) A program that reverses an integer using a while loop. 2) A program that finds the largest of three input numbers. 3) A program that prints the Fibonacci series up to a given number of terms using a for loop.

Uploaded by

mrajislm5374
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/ 2

1.

Reversing a number using While loop

#include <stdio.h>

int main() {

int n, reverse = 0, remainder;

printf("Enter an integer: ");


scanf("%d", &n);

while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}

printf("Reversed number = %d", reverse);

return 0;
}

Output

Enter an integer: 2345


Reversed number = 5432

2. Program to find largest of three input numbers


#include<stdio.h>
int main()
{
int num1,num2,num3;

printf("\nEnter value of num1, num2 and num3:");


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

if((num1>num2)&&(num1>num3))
printf("\n Number1 is greatest");
else if((num2>num3)&&(num2>num1))
printf("\n Number2 is greatest");
else
printf("\n Number3 is greatest");
return 0;
}
Output:

Enter value of num1, num2 and num3: 15 200 101


Number2 is greatest

Fibonacci Series in C using loop


#include<stdio.h>
int main()
{
int count, first_term = 0, second_term = 1, next_term, i;

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


scanf("%d",&count);

printf("First %d terms of Fibonacci series:\n",count);


for ( i = 0 ; i < count ; i++ )
{
if ( i <= 1 )
next_term = i;
else
{
next_term = first_term + second_term;
first_term = second_term;
second_term = next_term;
}
printf("%d\n",next_term);
}

return 0;
}

Output:

Enter the number of terms: 8


First 8 terms of Fibonacci series:
0
1
1
2
3
5
8
13

You might also like