SlideShare a Scribd company logo
1 of 3
/* 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() {
long int num,s=0,ch,sum;
clrscr();
printf("Enter any number: ");
scanf("%ld",&num);
printf("nnChoose: 1: obtain sum of digits non-recursivelynn");
printf(" 2: obtain sum of digits recursivelynnn");
printf("Your choice: ");
ch=getche();
switch(ch) {
case '1':
while(num!=0) {
s=s+(num%10);
num=num/10;
}
printf("nnnsum of digits = %dn",s);
break;
case '2':
s=sum+num;
printf("nnnSum of digits = %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
/* 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() {
unsigned i,num=25,c=1,fib;
clrscr();
for(i=0;i<num;i++) {
printf("%u ",fib*c);
c++;
}
getch();
}
fib(unsigned n) {
if(n==0)
return 0;
if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
Out Put

More Related Content

What's hot

Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
harman kaur
 

What's hot (20)

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
 
Progr3
Progr3Progr3
Progr3
 
.Cpp
.Cpp.Cpp
.Cpp
 
Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
 
Progr2
Progr2Progr2
Progr2
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
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 ...
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Metnum
MetnumMetnum
Metnum
 
Switch
SwitchSwitch
Switch
 
week-6x
week-6xweek-6x
week-6x
 
week-22x
week-22xweek-22x
week-22x
 
10740737 1599055096995598 1135912358_n
10740737 1599055096995598 1135912358_n10740737 1599055096995598 1135912358_n
10740737 1599055096995598 1135912358_n
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
program in c
program in cprogram in c
program in c
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 

Viewers also liked (16)

Copywriting for soft skill course
Copywriting for soft skill courseCopywriting for soft skill course
Copywriting for soft skill course
 
Organigrama ingles relatives cluses
Organigrama ingles relatives clusesOrganigrama ingles relatives cluses
Organigrama ingles relatives cluses
 
Duke of wellington collection honors battle of waterloo bicentennial
Duke of wellington collection honors battle of waterloo bicentennialDuke of wellington collection honors battle of waterloo bicentennial
Duke of wellington collection honors battle of waterloo bicentennial
 
The_Book_of_Capabilities_Reach Extension
The_Book_of_Capabilities_Reach ExtensionThe_Book_of_Capabilities_Reach Extension
The_Book_of_Capabilities_Reach Extension
 
Colours: I like eating colours
Colours: I like eating coloursColours: I like eating colours
Colours: I like eating colours
 
Sparql
SparqlSparql
Sparql
 
Sir John Hawkins
Sir John HawkinsSir John Hawkins
Sir John Hawkins
 
Excitement And Pbl
Excitement And PblExcitement And Pbl
Excitement And Pbl
 
Production diary summer
Production diary summerProduction diary summer
Production diary summer
 
Presentation3
Presentation3Presentation3
Presentation3
 
38 dead in Philippines ferry capsize
38 dead in Philippines ferry capsize38 dead in Philippines ferry capsize
38 dead in Philippines ferry capsize
 
Brandy
BrandyBrandy
Brandy
 
Active packaging by saeed ranjbaryan
Active packaging by saeed ranjbaryanActive packaging by saeed ranjbaryan
Active packaging by saeed ranjbaryan
 
Shutter island analysis
Shutter island analysisShutter island analysis
Shutter island analysis
 
Dobszóló DRUM SOLO
Dobszóló  DRUM  SOLODobszóló  DRUM  SOLO
Dobszóló DRUM SOLO
 
أشعة غاما
أشعة غاماأشعة غاما
أشعة غاما
 

Similar to New microsoft office word document

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C programs
C programsC programs
C programs
Minu S
 

Similar to New microsoft office word document (20)

cpract.docx
cpract.docxcpract.docx
cpract.docx
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Bca 1st year C langauge .pdf
Bca 1st year C langauge .pdfBca 1st year C langauge .pdf
Bca 1st year C langauge .pdf
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C programming
C programmingC programming
C programming
 
C programs
C programsC programs
C programs
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
C file
C fileC file
C file
 
C programs
C programsC programs
C programs
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Programming egs
Programming egs Programming egs
Programming egs
 
C lab
C labC lab
C lab
 

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 (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
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

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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...
 
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
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
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...
 
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...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
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
 
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
 
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
 
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
 
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
 

New microsoft office word document

  • 1. /* 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() { long int num,s=0,ch,sum; clrscr(); printf("Enter any number: "); scanf("%ld",&num); printf("nnChoose: 1: obtain sum of digits non-recursivelynn"); printf(" 2: obtain sum of digits recursivelynnn"); printf("Your choice: "); ch=getche(); switch(ch) { case '1': while(num!=0) { s=s+(num%10); num=num/10; } printf("nnnsum of digits = %dn",s); break; case '2': s=sum+num; printf("nnnSum of digits = %dn",s); break; } getch(); } sum(long n) {
  • 2. static s=0; if(n==0) return s; else { s=s+n%10; n=sum(n/10); return n; } } Out Put /* 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() { unsigned i,num=25,c=1,fib; clrscr(); for(i=0;i<num;i++) { printf("%u ",fib*c); c++; }
  • 3. getch(); } fib(unsigned n) { if(n==0) return 0; if(n==1) return 1; else return fib(n-1)+fib(n-2); } Out Put