Skip to main content

Posts

Showing posts from April, 2026

Online C Compiler - Programiz

  Codes Experiment 1 exp1 Aim: compute the time and space complexity of basic recursive and iterative functions using Big-O notation. #include <stdio.h> #include <time.h> // Recursive long long factR(int n){     return (n<=1)?1:n*factR(n-1); } int main(){     int n,i;     long long f;     clock_t s,e;     double t;     printf("Enter a number to find factorial: ");     scanf("%d",&n);     // Iterative     f=1;     s=clock();     for(i=1;i<=n;i++) f*=i;     e=clock();     t=(double)(e-s)/CLOCKS_PER_SEC;     printf("\n[Iterative] Factorial of %d = %lld",n,f);     printf("\n[Iterative] Time taken: %f seconds",t);     printf("\n[Iterative] Space Complexi...