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

C Programs for Fibonacci and Numbers

Uploaded by

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

C Programs for Fibonacci and Numbers

Uploaded by

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

Fibonacci Series

Fibonacci Series in C: In case of fibonacci series, next number is the sum of


previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. The first two
numbers of fibonacci series are 0 and 1.
-----------------------------------------------------------------------------------
-----------------------------
/* w.a.p to print fibonacci numbers upto N*/
#include<stdio.h>
void main()
{
int n1=0,n2=1,n3,i=2,n;
clrscr();
printf("Enter the number of elements:");
scanf("%d",&n);
printf("\n%d %d",n1,n2);
while(i<=n)
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
i++;
}
getch();
}
-----------------------------------------------------------------------------------
-----------------------
/* w.a.p to calculate sum of digit in given no */
#include<stdio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
s=0;
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("Sum of Digit=%d",s);
getch();
}
Output
Enter any No. 123
Sum of Digit=6
-----------------------------------------------------------------------------------
----------------------
/* w.a.p to change reverse of digit in given no */
#include<stdio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
s=0;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
printf("Reverse of Digit=%d",s);
getch();
}
Output
Enter any No. 123
Reverse: 321
-----------------------------------------------------------------------------------
-----------------------------
/* w.a.p to find out given number is palindrome or not */
#include<stdio.h>
void main()
{
int n,r,s=0,t;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
t=n;
s=0;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(t==s)
printf("Palindrome");
else
printf("Not a Palindrome");
getch();
}
Output
Enter any No. 121
Palindrome
-----------------------------------------------------------------------------------
-----------------------------
/*w.a.p to find out given no is palindrome number or not */
#include<stdio.h>
void main()
{
int n,r,s=0,t;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
t=n;
s=0;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(t==s)
printf("Palindrome Number");
else
printf("Not a palindrome Number");
getch();
}
Output
Enter any No. 121
Palindrome Number
-----------------------------------------------------------------------------------
-----------------------------
Armstrong Numbers:
153=1*1*1+5*5*5+3*3*3=153
0,1,153,370,371,407
-----------------------------------------------------------------------------------
-----------------------------
/* w.a.p to find out given no is armstrong or not */
#include<stdio.h>
void main()
{
int n,r,t,s=0;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
t=n;
s=0;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(s==t)
printf("Armstrong Number");
else
printf("Not a armstrong number");
getch();
}
Output
Enter any No. 153
Armstrong Number
-----------------------------------------------------------------------------------
-----------------------------
153=1*1*1+5*5*5+3*3*3
1+125+27=153
0,1,153,370,371,407
-----------------------------------------------------------------------------------
--------------------------
goto keyword: It is a skipping or jumpping statement. It is an unconditional match
statement.
syntax:
goto lablename;
{
set of statements;
}
labelname:
-----------------------------------------------------------------------------------
-----------------------------
/*w.a.p to calculate lucky number */
#include<stdio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("Enter any No.");
scanf("%d",&n);
next:
s=0;
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
if(s>10)
{
n=s;
goto next;
}
printf("Lucky Number=%d",s);
getch();
}
Output
Enter any No. 777
Lucky Number=3
-----------------------------------------------------------------------------------
-----------------------------

You might also like