SlideShare a Scribd company logo
1 of 2
/* Write a recursive function to obtain the first 25 numbers of a
Fibonacci sequence. In a Fibonacci sequence the sum of two successive
terms gives the third term. Following are the first few terms of the
Fibonacci sequence:
1 1 2 3 5 8 13 21 34 55 89... */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
unsigned i,n=25,a=1,fib;
for(i=0;i<n;i++) {
printf("%u ",fib*a);
a++;
}
getch();
}
fib(unsigned n) {
if(n==0)
return 0;
if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
Out Put
/* A 5-digit positive integer is entered through the keyboard, write a
function to calculate sum of digits of the 5-digit number:
(1) Without using recursion
(2) Using recursion */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
long int n,s=0,b,sum;
printf("Enter any 5-digit number: ");
scanf("%ld",&n);
printf("nnChoose : 1: sum of digits without recursivelynn");
printf("Or Choose : 2: sum of digits recursivelynnn");
printf("Your choice is = ");
b=getche();
switch(b) {
case '1':
while(n!=0) {
s=s+(n%10);
n=n/10;
}
printf("nnnThe sum of digits is = %dn",s);
break;
case '2':
s=sum+n;
printf("nnnThe Sum of digits is = %dn",s);
break;
}
getch();
}
sum(long n) {
static s=0;
if(n==0)
return s;
else {
s=s+n%10;
n=sum(n/10);
return n;
}
}
Out Put

More Related Content

What's hot

My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Senthil Kumar
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
alish sha
 

What's hot (20)

Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
A formalization of complex event stream processing
A formalization of complex event stream processingA formalization of complex event stream processing
A formalization of complex event stream processing
 
Prime number program in c
Prime number program in cPrime number program in c
Prime number program in c
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Linked list2
Linked list2Linked list2
Linked list2
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3Bcsl 033 data and file structures lab s1-3
Bcsl 033 data and file structures lab s1-3
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2Bcsl 033 data and file structures lab s5-2
Bcsl 033 data and file structures lab s5-2
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
 
Program in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointersProgram in ‘C’ language to implement linear search using pointers
Program in ‘C’ language to implement linear search using pointers
 
Matlab project
Matlab projectMatlab project
Matlab project
 
Ansi c
Ansi cAnsi c
Ansi c
 

Viewers also liked

Avcm content flow_080608-v2
Avcm content flow_080608-v2Avcm content flow_080608-v2
Avcm content flow_080608-v2
Debjani Roy
 
Arefjev text
Arefjev textArefjev text
Arefjev text
eid1
 
Virtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
Virtuális tanulási tér kialakítása az Öveges József Szakképző IskolábanVirtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
Virtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
Arpad Banhidi
 
Absinthe
AbsintheAbsinthe
Absinthe
oman2g
 

Viewers also liked (15)

Avcm content flow_080608-v2
Avcm content flow_080608-v2Avcm content flow_080608-v2
Avcm content flow_080608-v2
 
БРОШУРА 20 ГОДИНИ ЗА ДЕЦАТА - ПРВА ДЕТСКА АМБАСАДА ВО СВЕТОТ МЕЃАШИ 1992-2012
БРОШУРА 20 ГОДИНИ ЗА ДЕЦАТА - ПРВА ДЕТСКА АМБАСАДА ВО СВЕТОТ МЕЃАШИ 1992-2012БРОШУРА 20 ГОДИНИ ЗА ДЕЦАТА - ПРВА ДЕТСКА АМБАСАДА ВО СВЕТОТ МЕЃАШИ 1992-2012
БРОШУРА 20 ГОДИНИ ЗА ДЕЦАТА - ПРВА ДЕТСКА АМБАСАДА ВО СВЕТОТ МЕЃАШИ 1992-2012
 
Jaypee Boomerang Residency 9999963844 JP Boomerang Residency
Jaypee Boomerang Residency 9999963844 JP Boomerang ResidencyJaypee Boomerang Residency 9999963844 JP Boomerang Residency
Jaypee Boomerang Residency 9999963844 JP Boomerang Residency
 
Arefjev text
Arefjev textArefjev text
Arefjev text
 
RUCUG: 9. Sergey Khalyapin: Представляем XenDesktop 5
RUCUG: 9. Sergey Khalyapin: Представляем XenDesktop 5RUCUG: 9. Sergey Khalyapin: Представляем XenDesktop 5
RUCUG: 9. Sergey Khalyapin: Представляем XenDesktop 5
 
Virtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
Virtuális tanulási tér kialakítása az Öveges József Szakképző IskolábanVirtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
Virtuális tanulási tér kialakítása az Öveges József Szakképző Iskolában
 
SDPI Political Barometer Phase-II
SDPI Political Barometer Phase-IISDPI Political Barometer Phase-II
SDPI Political Barometer Phase-II
 
Telangana solar RFS Document 2014
Telangana solar RFS Document 2014Telangana solar RFS Document 2014
Telangana solar RFS Document 2014
 
GUSII MWALIMU SACCO TENDER DOCUMENTS 2015_2016
GUSII MWALIMU SACCO TENDER DOCUMENTS 2015_2016GUSII MWALIMU SACCO TENDER DOCUMENTS 2015_2016
GUSII MWALIMU SACCO TENDER DOCUMENTS 2015_2016
 
En trak
En trakEn trak
En trak
 
Jamaludin - Proses pada Sistem Operasi
Jamaludin - Proses pada Sistem OperasiJamaludin - Proses pada Sistem Operasi
Jamaludin - Proses pada Sistem Operasi
 
Absinthe
AbsintheAbsinthe
Absinthe
 
Avoid warts this summer
Avoid warts this summerAvoid warts this summer
Avoid warts this summer
 
Unit 7 lesson d
Unit 7  lesson dUnit 7  lesson d
Unit 7 lesson d
 
National geographic interactive january 2015
National geographic interactive january 2015 National geographic interactive january 2015
National geographic interactive january 2015
 

Similar to New microsoft office word document (2)

Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
You will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdfYou will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdf
malavshah9013
 

Similar to New microsoft office word document (2) (20)

Presentation 6 (1).pptx
Presentation 6 (1).pptxPresentation 6 (1).pptx
Presentation 6 (1).pptx
 
week4_python.docx
week4_python.docxweek4_python.docx
week4_python.docx
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
 
PYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfPYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdf
 
Functions
FunctionsFunctions
Functions
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
Hello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdfHello. This program has to be done in Eclipse(Program used to write .pdf
Hello. This program has to be done in Eclipse(Program used to write .pdf
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Algorithms with-java-1.0
Algorithms with-java-1.0Algorithms with-java-1.0
Algorithms with-java-1.0
 
Functions Practice Sheet.docx
Functions Practice Sheet.docxFunctions Practice Sheet.docx
Functions Practice Sheet.docx
 
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAMPROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS  - SARASWATHI RAMALINGAM
PROGRAMMING IN C EXAMPLE PROGRAMS FOR NEW LEARNERS - SARASWATHI RAMALINGAM
 
140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...
 
140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...
 
140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...140+ Basic Python Programs This resource can assist you in preparing for your...
140+ Basic Python Programs This resource can assist you in preparing for your...
 
Assignment no 5
Assignment no 5Assignment no 5
Assignment no 5
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
You will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdfYou will be implementing the following functions. You may modify the.pdf
You will be implementing the following functions. You may modify the.pdf
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 

More from Syed Umair (20)

Assignement code
Assignement codeAssignement code
Assignement code
 
Tree 4
Tree 4Tree 4
Tree 4
 
Title page
Title pageTitle page
Title page
 
S.k
S.kS.k
S.k
 
Q.a
Q.aQ.a
Q.a
 
Prog
ProgProg
Prog
 
Perception
PerceptionPerception
Perception
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
M.b
M.bM.b
M.b
 
C++ 4
C++ 4C++ 4
C++ 4
 
B.g
B.gB.g
B.g
 
Assignement of programming & problem solving
Assignement of programming & problem solvingAssignement of programming & problem solving
Assignement of programming & problem solving
 
Assignement of discrete mathematics
Assignement of discrete mathematicsAssignement of discrete mathematics
Assignement of discrete mathematics
 
A.i
A.iA.i
A.i
 
H m
H mH m
H m
 
Prog
ProgProg
Prog
 
Assignment c++12
Assignment c++12Assignment c++12
Assignment c++12
 
Assignement of discrete mathematics
Assignement of discrete mathematicsAssignement of discrete mathematics
Assignement of discrete mathematics
 
Assignement c++
Assignement c++Assignement c++
Assignement c++
 
Truth table a.r
Truth table a.rTruth table a.r
Truth table a.r
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

New microsoft office word document (2)

  • 1. /* Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89... */ #include<stdio.h> #include<conio.h> void main() { clrscr(); unsigned i,n=25,a=1,fib; for(i=0;i<n;i++) { printf("%u ",fib*a); a++; } getch(); } fib(unsigned n) { if(n==0) return 0; if(n==1) return 1; else return fib(n-1)+fib(n-2); } Out Put /* A 5-digit positive integer is entered through the keyboard, write a function to calculate sum of digits of the 5-digit number: (1) Without using recursion (2) Using recursion */ #include<stdio.h> #include<conio.h> void main() { clrscr(); long int n,s=0,b,sum; printf("Enter any 5-digit number: "); scanf("%ld",&n);
  • 2. printf("nnChoose : 1: sum of digits without recursivelynn"); printf("Or Choose : 2: sum of digits recursivelynnn"); printf("Your choice is = "); b=getche(); switch(b) { case '1': while(n!=0) { s=s+(n%10); n=n/10; } printf("nnnThe sum of digits is = %dn",s); break; case '2': s=sum+n; printf("nnnThe Sum of digits is = %dn",s); break; } getch(); } sum(long n) { static s=0; if(n==0) return s; else { s=s+n%10; n=sum(n/10); return n; } } Out Put