C Programming by Jena Sisir Kumar;
Author:Jena, Sisir Kumar; [Jena, Sisir Kumar]
Language: eng
Format: epub
Publisher: CRC Press LLC
Published: 2021-11-21T00:00:00+00:00
By analyzing the above Program 9.5, we conclude that if we solve multiple works inside a single function then the program size increases and is prone to errors. Debugging of the above program is also difficult. To avoid this difficulty, we can use the concept of a function. We can separate the above functionality into three functions as shown in Figure 9.7.
Figure 9.7 Separating functionality using different functions.
Program 9.5
1. #include<stdio.h> 2. void main() 3. { 4. int N, i, sum=0, count=0; 5. printf("
Enter a number: "); 6. scanf("%d", &N); 7. 8. /*Code to check whether the number is prime or not*/ 9. for(i=1;i<=N;i++) 10. { 11. if(N%i==0) 12. count=count+1; 13. } 14. if(count==2) 15. printf 16. else 17. printf("
THE NUMBER IS NOT A PRIME NUMBER"); 18. /*Code to check whether the number is a perfect number or not*/ 19. 20.for(i=1;i<=N/2;i++) 21. { 22. if(N%i==0) 23. sum=sum+i; 24. } 25. if(sum==N) 26. printf("
THE NUMBER IS A PERFECT NUMBER"); 27. else 28. printf("
THE NUMBER IS NOT A PERFECT NUMBER"); 29. }
Output:
Run-1
Enter a number: 28
THE NUMBER IS NOT A PRIME NUMBER
THE NUMBER IS A PERFECT NUMBER
Run-2
Enter a number: 43
THE NUMBER IS A PRIME NUMBER
THE NUMBER IS NOT A PERFECT NUMBER
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25280)
Hello! Python by Anthony Briggs(24331)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23419)
Kotlin in Action by Dmitry Jemerov(22500)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21953)
Dependency Injection in .NET by Mark Seemann(21835)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20699)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19514)
Grails in Action by Glen Smith Peter Ledbrook(18592)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17028)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15836)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13683)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11847)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11149)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10619)
Hit Refresh by Satya Nadella(9185)
The Kubernetes Operator Framework Book by Michael Dame(8560)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8399)
Robo-Advisor with Python by Aki Ranin(8347)