SELECTION SORT: #include<stdio.h> #include<conio.h> #include<math.h> #include<time.h> #define n 10000 void selection_sort(int[]); unsigned long int count=0; void main() { int a[n]; int choice,i; clrscr(); printf("1.Sorted Data 2.Random Data \n"); scanf("%d",&choice); switch(choice) { case 1: for(i=0;i<n;i++) { a[i]=i+1; } selection_sort(a); break; case 2: for(i=0;i<n;i++) { a[i]=n-i;
Implement functions to print nth Fibonacci number using iteration and recursive method. Compare the performance of two methods by counting number of steps executed on various inputs. Also draw a comparative chart. (Fibonacci series 1, 1, 2, 3, 5, 8….. Here 8 is the 6th Fibonacci number) #include<stdio.h> #include<conio.h> int iteration(int); int recursive(int); int count=0; void main() { int n,choice,ans; clrscr(); printf("\nenter nth number : "); scanf("%d",&n); printf(“\n==iteration==”); ans=iteration(n); printf(“\nans=%d\ncount=%d”,ans,count); printf(“\n\n==recursive==”); ans=recursive(n); printf("\nans=%d\ncount=%d",ans,count); getch(); } int iteration(int n) { int f=1,s=1,t,i; count++; count++; for(i=3;i<=n;i++) { t=f+s; count++; f=s; count++; s=t; count++; } count++; return t; } int recursive(int n) { count++; if(n==0 || n==1) { cou
👍
ReplyDelete