Basic 'C' Language Programs

Welcome to our comprehensive collection of C programming examples. C is a powerful general-purpose programming language that is widely used for system programming and embedded systems. In this section, you will find a variety of basic to advanced C programs that demonstrate fundamental concepts such as arrays, pointers, strings, and data structures. These examples are designed to help beginners build a strong foundation and experienced developers refresh their knowledge.

1. Single Character Input and Output

Concept: Demonstrates reading and writing individual characters efficiently using standard library functions getchar() and putchar() from <stdio.h>.

character_io.c


#include <stdio.h>

int main() {
    char c; // Variable to hold the character
    
    printf("Enter any character: ");
    
    // getchar() reads a single character from standard input
    c = getchar(); 
    
    printf("The Given Character is: ");
    
    // putchar() writes a single character to standard output
    putchar(c); 
    
    printf("\n");
    return 0;
}
              
Analysis
  • Time Complexity: O(1) - The program executes in constant time regardless of input.
  • Space Complexity: O(1) - Only a single char variable is allocated in memory.
Output Console
Enter any character: A
The Given Character is: A

2. Reading and Displaying Data Types (scanf & printf)

Concept: Demonstrates formatted data entry and console rendering for integer and floating-point variables using standard format specifiers (%d, %f).

program_2.c

//2 Data Input and output Example
#include <stdio.h>
int main()
{
    int a,b,c;
    float amount=4500.50;
    printf("Enter a,b,c values"); //prompt message
    scanf("%d",&a); //reading data
    scanf("%d",&b);
    scanf("%d",&c);
    printf("A=%d B=%d C=%d",a,b,c); //out put
    printf("\nAmount=%.2f",amount); //.2f means it shows only 2 decimals
    return 0;
}
Expected Output:
Enter a,b,c valuesA=10 B=20 C=30 Amount=4500.50
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

3. Symbolic Constants using #define

Concept: Demonstrates declaring immutable compile-time constants using the #define preprocessor directive to compute circle area and circumference.

program_3.c

//3.Symbolic contstant Example
#include <stdio.h>
#define PI 3.1416 //this way of declaration Symbolic constants no need data type no need equal for assign
int main()
{
    float r,area,peri;
    printf("Enter radius value");
    scanf("%f",&r);
    area=PI*r*r;
    peri=2*PI*r;
    printf("\n%.2f Radius, Area is %.2f and Its Perimeter is %.2f",r,area,peri);
    return 0;
}
Expected Output:
Enter radius value 10.00 Radius, Area is 314.16 and Its Perimeter is 62.83
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

4. Preprocessor Macros for Input/Output Aliases

Concept: Shows how #define macro substitutions can establish readable shorthand aliases for standard I/O library functions.

program_4.c

//4.Symbolic constants usage example
#include <stdio.h>
#define PI 3.1416
#define P printf // instead of printf you can also use P, becuase we define P as printf
#define S scanf// instead of scanf you can also use P, becuase we define S as scanf
int main()
{
    float r,area,peri;
    P("Enter radius value");
    S("%f",&r);
    area=PI*r*r;
    peri=2*PI*r;
    P("\n%.2f Radius, Area is %.2f and Its Perimeter is %.2f",r,area,peri);
    return 0;
}
Expected Output:
Enter radius value 10.00 Radius, Area is 314.16 and Its Perimeter is 62.83
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

5. Simple Interest Calculation

Concept: Illustrates implementing mathematical formulas in C using arithmetic operators and expressions: (principal * time * rate) / 100.

program_5.c

//5.Simple Interest Calculation(pnr/100)
#include <stdio.h>
int main()
{
    float capital,intrest_rate,no_of_years,simple_intreset,si;
    printf("Enter Capital");
    scanf("%f",&capital);
    printf("Enter Intreset Rate");
    scanf("%f", & intrest_rate);
    printf("Enter No of Years");
    scanf("%f",&no_of_years);
    si=(capital*intrest_rate*no_of_years)/100;
    printf("\nCapital:%.2f",capital);
    printf("\nInterest Rate:%.2f",intrest_rate);
    printf("\nNo of Years:%.2f",no_of_years);
    printf("\nSimple Interest on above data:%.2f",si);
    return 0;
}
Expected Output:
Enter CapitalEnter Intreset RateEnter No of Years Capital:10.00 Interest Rate:20.00 No of Years:30.00 Simple Interest on above data:60.00
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Control Statements

6. If-Else Decision Making

Concept: Evaluates relational conditions to execute alternative execution paths using standard if...else control flow constructs.

program_6.c

//1 Simple if...else Statements
#include <stdio.h>
int main()
{
    int age;
    printf("Enter Age");
    scanf("%d",&age);
    //printf("%s",age>17 ? "Eligible" : "Not Eligible");
    if(age>17)
      printf("Eligible");
    else
      printf("Not Eligible");

    return 0;
}
//Or
// no need Brace Brackets if your using after if one statement after else one statement other wise you should place brackets 
    int main()
    {
    int age;
    printf("Enter Age");
    scanf("%d",&age);
    //printf("%s",age>17 ? "Eligible" : "Not Eligible");
    if(age>17) 
      printf("Eligible");
    else 
      printf("Not Eligible");
    return 0;
    }
Expected Output:
Enter Age 17 Not Eligible or Enter Age 19 Eligible
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

7. Nested If-Else Statements

Concept: Demonstrates multi-tier condition evaluation where conditional branches contain nested decision-making blocks.

program_7.c

//control Statements(if...else Nested) Example
#include <stdio.h>
int main()
{
    int score;
    char name[20];
    printf("Enter Player Name");
    scanf("%s",name);
    printf("Enter Score");
    scanf("%d",&score);
    if(score==0)
    {
        printf("%s Plays %d and he is  Dock Out",name,score);
    }
    else if(score>0 && score<50)
    {
        printf("%s Plays %d and he is  Below Half Century",name,score);
    }
    else if(score==50)
    {
        printf("%s Plays %d and he is  Half Century",name,score);
    }
    else if(score>50 && score<100)
    {
        printf("%s Plays %d and he is  Above Half Century",name,score);
    }
    else if(score==100)
    {
        printf("%s Plays %d and he is  Century",name,score);
    }
    else if(score>100 && score<150)
    {
        printf("%s Plays %d and he is  Above Century",name,score);
    }
    else if(score==150)
    {
        printf("%s Plays %d and he is  One and Half Century",name,score);
    }
    else if(score>150 && score<200)
    {
        printf("%s Plays %d and he is  Above One and Half Century",name,score);
    }
    else if(score==200)
    {
     printf("%s Plays %d and he is  Double Century",name,score);   
    }
    else if(score>200)
    {
        printf("%s Plays %d and he is Above Double Century",name,score);
    }
    return 0;
}
Expected Output:
Enter Player Name Rohit Enter Score 100 Rohit Plays 100 and he is Century
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

8. Else-If Ladder: Score Classification

Concept: Demonstrates an else if ladder structure to evaluate multiple score thresholds and classify performance milestones.

program_8.c

#include <stdio.h>
int main()
{
    int score;
    char name[20];
    printf("Enter Player Name");
    scanf("%s",name);
    printf("Enter Score");
    scanf("%d",&score);
    if(score==0)
    {
        printf("%s Plays %d and he is  Dock Out",name,score);
    }
    else 
    {
        if(score>0 && score<50)
        {
        printf("%s Plays %d and he is  Below Half Century",name,score);
        }
        else
        {
            if(score==50)
            {
            printf("%s Plays %d and he is  Half Century",name,score);
            }
            else
            {
                if(score>50 && score<100)
                {
                printf("%s Plays %d and he is  Above Half Century",name,score);
                }
                    else
                    {
                    if(score==100)
                    {
                    printf("%s Plays %d and he is  Century",name,score);
                    }
                    else
                    {
                        if(score>100 && score<150)
                        {
                        printf("%s Plays %d and he is  Above Century",name,score);
                         }
                        else
                        {
                            if(score==150)
                            {
                            printf("%s Plays %d and he is  One and Half Century",name,score);
                            }
                            else
                            {
                                if(score>150 && score<200)
                                {
                                printf("%s Plays %d and he is  Above One and Half Century",name,score);
                                }
                                else
                                {
                                    if(score==200)
                                    {
                                     printf("%s Plays %d and he is  Double Century",name,score);   
                                    }
                                    else
                                    {
                                        if(score>200)
                                        {
                                            printf("%s Plays %d and he is Above Double Century",name,score);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
            
    return 0;
}
Expected Output:
Enter Player Name Rohit Enter Score 100 Rohit Plays 100 and he is Century
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

9. Multiplication Table using While Loop

Concept: Demonstrates repetitive arithmetic operations and formatted tabular output generation using the entry-controlled while loop.

program_9.c

//4 Print Multiple Table using While Loop
//multiple table example
#include <stdio.h>

int main()
{
   int n,i;
   printf("Enter n value");
   scanf("%d",&n);
   i=1;
   while(i<=10)
   {
       printf("\n%dX%d=%d",n,i,n*i);
       i++;
   }
    return 0;
}
Expected Output:
Enter n value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

10. Nested While Loops

Concept: Illustrates multi-dimensional repetition where an inner while loop completes its cycle for each iteration of the outer loop.

program_10.c

//nested while loop
//example of multiple tables between range
#include <stdio.h>
int main()
{
   int low,high,i;
   printf("Enter low,high value");
   scanf("%d%d",&low,&high);
   while(low<=high)
   {
       i=1;
       while(i<=10)
       {
           printf("\n%dX%d=%d",low,i,low*i);
           i++;
       }
      low++;
       
   }
    return 0;
}
Expected Output:
Enter low,high value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100 11X1=11 11X2=22 11X3=33 11X4=44 11X5=55 11X6=66 11X7=77 11X8=88 11X9=99 11X10=110 12X1=12 12X2=24 12X3=36 12X4=48 12X5=60 12X6=72 12X7=84 12X8=96 12X9=108 12X10=120 13X1=13 13X2=26 13X3=39 13X4=52 13X5=65 13X6=78 13X7=91 13X8=104 13X9=117 13X10=130 14X1=14 14X2=28 14X3=42 14X4=56 14X5=70 14X6=84 14X7=98 14X8=112 14X9=126 14X10=140 15X1=15 15X2=30 15X3=45 15X4=60 15X5=75 15X6=90 15X7=105 15X8=120 15X9=135 15X10=150 16X1=16 16X2=32 16X3=48 16X4=64 16X5=80 16X6=96 16X7=112 16X8=128 16X9=144 16X10=160 17X1=17 17X2=34 17X3=51 17X4=68 17X5=85 17X6=102 17X7=119 17X8=136 17X9=153 17X10=170 18X1=18 18X2=36 18X3=54 18X4=72 18X5=90 18X6=108 18X7=126 18X8=144 18X9=162 18X10=180 19X1=19 19X2=38 19X3=57 19X4=76 19X5=95 19X6=114 19X7=133 19X8=152 19X9=171 19X10=190 20X1=20 20X2=40 20X3=60 20X4=80 20X5=100 20X6=120 20X7=140 20X8=160 20X9=180 20X10=200
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

11. Loop Control using Continue Statement

Concept: Demonstrates bypassing the remainder of the current loop body and jumping directly to the next iteration using continue.

program_11.c

//while with continue statement
//if any doubt please watch my channel c language course
#include <stdio.h>
int main()
{
   int low,high,i;
   printf("Enter low,high value");
   scanf("%d%d",&low,&high);
   while(low<=high)
   {
        if(low==5 || low==8)
        {
            low++;
           continue;
        }
       i=1;
       while(i<=10)
       {
           printf("\n%dX%d=%d",low,i,low*i);
           i++;
       }
      low++;
       
   }
    return 0;
}
Expected Output:
Enter low,high value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100 11X1=11 11X2=22 11X3=33 11X4=44 11X5=55 11X6=66 11X7=77 11X8=88 11X9=99 11X10=110 12X1=12 12X2=24 12X3=36 12X4=48 12X5=60 12X6=72 12X7=84 12X8=96 12X9=108 12X10=120 13X1=13 13X2=26 13X3=39 13X4=52 13X5=65 13X6=78 13X7=91 13X8=104 13X9=117 13X10=130 14X1=14 14X2=28 14X3=42 14X4=56 14X5=70 14X6=84 14X7=98 14X8=112 14X9=126 14X10=140 15X1=15 15X2=30 15X3=45 15X4=60 15X5=75 15X6=90 15X7=105 15X8=120 15X9=135 15X10=150 16X1=16 16X2=32 16X3=48 16X4=64 16X5=80 16X6=96 16X7=112 16X8=128 16X9=144 16X10=160 17X1=17 17X2=34 17X3=51 17X4=68 17X5=85 17X6=102 17X7=119 17X8=136 17X9=153 17X10=170 18X1=18 18X2=36 18X3=54 18X4=72 18X5=90 18X6=108 18X7=126 18X8=144 18X9=162 18X10=180 19X1=19 19X2=38 19X3=57 19X4=76 19X5=95 19X6=114 19X7=133 19X8=152 19X9=171 19X10=190 20X1=20 20X2=40 20X3=60 20X4=80 20X5=100 20X6=120 20X7=140 20X8=160 20X9=180 20X10=200
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

12. Loop Control using Break Statement

Concept: Demonstrates early loop termination upon meeting a specified termination condition using the break statement.

program_12.c

//while with Break statement
//if any doubt please watch my channel c language course
#include <stdio.h>
int main()
{
   int low,high,i;
   printf("Enter low,high value");
   scanf("%d%d",&low,&high);
   while(low<=high)
   {
        if(low==5)
        {
           
          break;
        }
       i=1;
       while(i<=10)
       {
           printf("\n%dX%d=%d",low,i,low*i);
           i++;
       }
      low++;
       
   }
    return 0;
}
Expected Output:
Enter low,high value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100 11X1=11 11X2=22 11X3=33 11X4=44 11X5=55 11X6=66 11X7=77 11X8=88 11X9=99 11X10=110 12X1=12 12X2=24 12X3=36 12X4=48 12X5=60 12X6=72 12X7=84 12X8=96 12X9=108 12X10=120 13X1=13 13X2=26 13X3=39 13X4=52 13X5=65 13X6=78 13X7=91 13X8=104 13X9=117 13X10=130 14X1=14 14X2=28 14X3=42 14X4=56 14X5=70 14X6=84 14X7=98 14X8=112 14X9=126 14X10=140 15X1=15 15X2=30 15X3=45 15X4=60 15X5=75 15X6=90 15X7=105 15X8=120 15X9=135 15X10=150 16X1=16 16X2=32 16X3=48 16X4=64 16X5=80 16X6=96 16X7=112 16X8=128 16X9=144 16X10=160 17X1=17 17X2=34 17X3=51 17X4=68 17X5=85 17X6=102 17X7=119 17X8=136 17X9=153 17X10=170 18X1=18 18X2=36 18X3=54 18X4=72 18X5=90 18X6=108 18X7=126 18X8=144 18X9=162 18X10=180 19X1=19 19X2=38 19X3=57 19X4=76 19X5=95 19X6=114 19X7=133 19X8=152 19X9=171 19X10=190 20X1=20 20X2=40 20X3=60 20X4=80 20X5=100 20X6=120 20X7=140 20X8=160 20X9=180 20X10=200
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

13. Post-Tested Loop: Do-While Structure

Concept: Demonstrates guaranteed single execution followed by conditional validation using the exit-controlled do...while loop.

program_13.c

//do while program example
#include <stdio.h>
int main()
{

    int amount,total_amount=0;
    do{
        printf("\nEnter Amount");
        scanf("%d",&amount);
        if(amount>0)
        {
            total_amount=total_amount+amount;
            printf("\nCumilative Amount=%d",total_amount);
        }
    }while(amount>0);
    return 0;
}
Expected Output:
[Execution Timeout: Program may require complex interactive input]
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

14. Iteration using the For Loop

Concept: Combines counter initialization, condition testing, and increment/decrement within a compact, structured for statement.

program_14.c

//for loop
//we can also write using while also
#include <stdio.h>
int main()
{

    int size_of_line,i;
    printf("Enter size_of_line value");
    scanf("%d",&size_of_line);
   /* i=1;
    while(i<=size_of_line)
    {
        printf("-");
        i++;
    }*/
    for(i=1;i<=size_of_line;i++)
    {
       printf("-"); 
    }

    return 0;
}
Expected Output:
Enter size_of_line value----------
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

15. Prime Number Verification (Basic Method)

Concept: Tests whether a positive integer is prime by iterating through potential factors using the modulus remainder operator.

program_15.c

//Prime number Program model 1
#include <stdio.h>
int main()
{

    int isPrime=0,num,i;
    printf("Enter any number");
    scanf("%d",&num);
    for(i=1;i<=num;i++)
    {
        if(num%i==0)
        {
            isPrime++;
        }
    }   
    if(isPrime==2)
    {
        printf("This is Prime Number %d",num);
    }
    else
    {
        printf("This  is Not Prime Number %d",num);
    }
    return 0;
}
Expected Output:
Enter any numberThis is Not Prime Number 10
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

16. Prime Number Verification (Optimized Method)

Concept: Optimizes prime verification efficiency by minimizing iteration passes and breaking immediately upon detecting any non-trivial factor.

program_16.c

//Prime number Program model 2
#include <stdio.h>
int main()
{
    int isPrime=0,num,i;
    printf("Enter any number");
    scanf("%d",&num);
    for(i=2;i<num;i++)
    {
        if(num%i==0)
        {
            isPrime++;
            break;
        }
    }   
    if(isPrime==0)
    {
        printf("This is Prime Number %d",num);
    }
    else
    {
        printf("This  is Not Prime Number %d",num);
    }
    return 0;
}
Expected Output:
Enter any numberThis is Not Prime Number 10
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

17. Right-Angled Number Triangle Pattern

Concept: Generates incremental numeric triangle patterns using nested loop coordination between row counters and column indices.

program_17.c

/*
1 
12 
123
1234
12345
*/
#include <stdio.h>

int main()
{
  int n,i,j;
  printf("Enter n value");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
      for(j=1;j<=i;j++)
      {
          //printf("%2d",i);//it set 2 digits width
          printf("* ");
      }
      printf("\n");
  }

    return 0;
}
Expected Output:
Enter n value* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

18. Diamond & Pyramid Number Pattern

Concept: Constructs symmetric geometric number patterns using ascending and descending nested loop control logic.

program_18.c

/*
1 
12 
123
1234
12345
1234
123 
12
1
*/
#include <stdio.h>

int main()
{
  int n,i,j;
  printf("Enter n value");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
      for(j=1;j<=i;j++)
      {
          //printf("%2d",i);//it set 2 digits width
          printf("* ");
      }
      printf("\n");
  }
  for(i=n-1;i>=1;i--)
  {
      for(j=1;j<=i;j++)
      {
          //printf("%2d",i);//it set 2 digits width
          printf("* ");
      }
      printf("\n");
  }

    return 0;
}
Expected Output:
Enter n value* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Arrays

19. One-Dimensional Array: Reversal & Traversal

Concept: Demonstrates contiguous memory allocation, reading an array of numbers, and outputting elements in forward and reversed order.

program_19.c

#include <stdio.h>
int main()
{
  int a[20],n,i;
  printf("Enter n values");
  scanf("%d",&n);
  printf("Enter %d elements",n);
  for(i=0;i=0;i--)
  {
      printf("%2d",a[i]);
  }
    return 0;
}
Expected Output:
Enter n valuesEnter 10 elements The Elements are in Original Order 2030 5 1 2 3 4 5100 0 The Elements are in Reverse Order 0100 5 4 3 2 1 53020
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

20. Array Processing: Above-Average Numbers

Concept: Computes the statistical average of an array and filters elements that exceed the calculated mean threshold.

program_20.c

//Take n numbers and print those at the same time print above average numbers
#include <stdio.h>

int main()
{
  int a[20],n,i,sum=0,avg;
  printf("Enter n values");
  scanf("%d",&n);
  printf("Enter %d elements",n);
  for(i=0;i<n;i++)
  {
      scanf("%d",&a[i]);
      sum=sum+a[i];
  }
  printf("\nThe Given Numbers are ");
  for(i=0;i<n;i++)
  {
      printf("%3d",a[i]);
  }
  printf("\nThe Above Numbers sum is %d",sum);
  avg=sum/n;
  printf("\nThe Above Numbers Average is %d",avg);
  printf("\nThe Above Average Numbers are ");
    for(i=0;i<n;i++)
  {
      if(a[i]>avg)
      {
      printf("%3d",a[i]);
      }
  }
  
    return 0;
}
Expected Output:
Enter n valuesEnter 10 elements The Given Numbers are 20 30 5 1 2 3 4 5100 0 The Above Numbers sum is 170 The Above Numbers Average is 17 The Above Average Numbers are 20 30100
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

21. Two-Dimensional Array (Matrix Operations)

Concept: Demonstrates row-column grid indexing, nested array iteration, and multi-dimensional matrix operations in C.

program_21.c

//Two Dimensional Array Example
#include <stdio.h>
int main()
{
 int mat[5][5],r,c,i,j;
 printf("Enter row and columns values");
 scanf("%d%d",&r,&c);
 printf("Enter %dX%d Matrix values",r,c);
 for(i=0;i<r;i++)
 {
     for(j=0;j<c;j++)
     {
         scanf("%d",&mat[i][j]);
     }
 }
  printf("\nThe Matrix is \n");
   for(i=0;i<r;i++)
 {
     for(j=0;j<c;j++)
     {
         printf("%3d",mat[i][j]);
     }
     printf("\n");
 }
    return 0;
}
Expected Output:
Enter row and columns valuesEnter 10X20 Matrix values The Matrix is 30 5 1 2 3 4 5100-112200275232765-2021655376 51 14 0-112279061732765-135859808032759 1 0 4 5100-112200275232765-2021655376 51 14 0-112279061732765-135859808032759 1 0-112200137632765-2021655376 51-2021655360 -2021655376 51 14 0-112279061732765-135859808032759 1 0-112200137632765-2021655376 51-2021655360 51 16 2 1 0 32765-135859808032759 1 0-112200137632765-2021655376 51-2021655360 51 11 3 1 0-135862247032759 232759 2 -112200137632765-2021655376 51-2021655360 51 6 4 1 0-135862247032759 232759 2 0-112200137632765-135862121632759 51 1 5 1 0-135862247032759 232759 2 0-112200137632765-135862121632759-2021655300 51 0 0 0 -135862247032759 232759 2 0-112200137632765-135862121632759-2021655300 51 0 0 0 0 0 0 0 0 0-112200137632765-135862121632759-2021655300 51 0 0 0 0 0 0 0 0 0 0 0 0 0 -2021655300 51 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Got ... Switch .. Case .. Break

22. Unconditional Branching using Goto

Concept: Illustrates jumping execution unconditionally to designated label markers using the goto keyword.

program_22.c

//1 A Simple Goto Example
#include <stdio.h>
int main()
{
int n,i;
printf("Enter n value");
scanf("%d",&n);
i=1;
A:
printf("\n%dX%d=%d",n,i,n*i);
i++;
if(i<=10) goto A;

    return 0;
}
Expected Output:
Enter n value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

23. Multi-Branch Control with Nested Goto

Concept: Demonstrates structured control flow management using multiple conditional label targets and goto statements.

program_23.c

//Nested Goto Statements Example
#include <stdio.h>
int main()
{
int min,max,i;
printf("Enter min,max value");
scanf("%d%d",&min,&max);

A:   i=1;
B:   printf("\n%dX%d=%d",min,i,min*i);
     i++;
     if(i<=10) goto B;
C:   min++;
     if(min%2==0) goto C;
if(min<=max) goto A;

    return 0;
}
Expected Output:
Enter min,max value 10X1=10 10X2=20 10X3=30 10X4=40 10X5=50 10X6=60 10X7=70 10X8=80 10X9=90 10X10=100 11X1=11 11X2=22 11X3=33 11X4=44 11X5=55 11X6=66 11X7=77 11X8=88 11X9=99 11X10=110 13X1=13 13X2=26 13X3=39 13X4=52 13X5=65 13X6=78 13X7=91 13X8=104 13X9=117 13X10=130 15X1=15 15X2=30 15X3=45 15X4=60 15X5=75 15X6=90 15X7=105 15X8=120 15X9=135 15X10=150 17X1=17 17X2=34 17X3=51 17X4=68 17X5=85 17X6=102 17X7=119 17X8=136 17X9=153 17X10=170 19X1=19 19X2=38 19X3=57 19X4=76 19X5=95 19X6=114 19X7=133 19X8=152 19X9=171 19X10=190
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

24. Multiway Selection: Switch-Case Structure

Concept: Demonstrates clear, menu-driven multiway branching based on constant integer expressions using switch, case, and break.

program_24.c

//Switch..Case..Break Example
#include <stdio.h>
int main()
{

int a,b,c;
printf("Enter a,b values");
scanf("%d%d",&a,&b);
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n5.Modulus");
printf("\n6.Exit");
printf("\nEnter your choice ..");
scanf("%d",&c);
switch(c)
{
    case 1:
    printf("\nA+B=%d",a+b);
    break;
    case 2:
    printf("\nA-B=%d",a-b);
    break;
    case 3:
    printf("\nAXB=%d",a*b);
    break;
    case 4:
    printf("\nA/B=%d",a/b);
    break;
    case 5:
    printf("\nA%B=%d",a%b);
    break;
    default:
    printf("\nYour Exit the Program.");
    
}
    return 0;
}
Expected Output:
Enter a,b values 1.Addition 2.Subtraction 3.Multiplication 4.Division 5.Modulus 6.Exit Enter your choice .. Your Exit the Program.
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

25. Switch-Case Combined with Branching Labels

Concept: Combines switch-case decision branching with label jumps for continuous menu-driven application loops.

program_25.c

//Switch..Case..Goto Example
#include <stdio.h>

int main()
{
int a,b,c;
printf("Enter a,b values");
scanf("%d%d",&a,&b);
printf("\n1.Addition");
printf("\n2.Subtraction");
printf("\n3.Multiplication");
printf("\n4.Division");
printf("\n5.Modulus");
printf("\n6.Exit");
A:
printf("\nEnter your choice ..");
scanf("%d",&c);
switch(c)
{
    case 1:
    printf("\nA+B=%d",a+b);
    //break;
    goto A;
    case 2:
    printf("\nA-B=%d",a-b);
    //break;
    goto A;
    case 3:
    printf("\nAXB=%d",a*b);
    //break;
    goto A;
    case 4:
    printf("\nA/B=%d",a/b);
    //break;
    goto A;
    case 5:
    printf("\nA%B=%d",a%b);
    //break;
    goto A;
    default:
    printf("\nYour Exit the Program.");
    
}
    return 0;
}
Expected Output:
Enter a,b values 1.Addition 2.Subtraction 3.Multiplication 4.Division 5.Modulus 6.Exit Enter your choice .. Your Exit the Program.
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

String Built in Functions

26. Reading and Displaying String Data

Concept: Demonstrates reading multi-word string sequences and printing character arrays using standard string I/O functions.

program_26.c

// Read String information and print those
#include <stdio.h>
int main()
{

 char name[20],course[15],city[20];
 printf("Enter Name");
 scanf("%s",name);
 printf("Enter course");
 scanf("%s",course);
 printf("Enter city");
 scanf("%s",city);
 printf("\nName:%s",name);
 printf("\nCourse:%s",course);
 printf("\nCity:%s",city);
 
    return 0;
}
Expected Output:
Enter NameEnter courseEnter city Name:10 Course:20 City:30
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

27. Two-Dimensional Character Array (Name List)

Concept: Stores multiple name strings within a 2D character matrix and iterates through records using row-wise indexing.

program_27.c

//Read n names and print those
#include <stdio.h>
int main()
{
int n,i;
char names[30][20];
    printf("\nEnter n value");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s",names[i]);
    }
    for(i=0;i<n;i++)
    {
        printf("\n%d. %s",i+1,names[i]);
    }
    return 0;
}
Expected Output:
Enter n value 1. 20 2. 30 3. 5 4. 1 5. 2 6. 3 7. 4 8. 5 9. 100 10.
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

28. String Uppercase Conversion using strupr()

Concept: Converts lowercase alphabetical characters to uppercase representation using string manipulation functions.

program_28.c

//string upper using strupr();
//string lower using strlwr();
//string length using strlen();
//string copy using strcpy();
//string concatanation using strcat();
//string reverse using strrev();
#include <stdio.h>
#include <string.h>
int main()
{
    char name[20],copy_name[20];
    printf("Enter any Name");
    scanf("%s",name);
    strcpy(copy_name,name);
    printf("\nOriginal:%s",name);
    printf("\nUppercase:%s",strupr(name));
    printf("\nLowercase:%s",strlwr(name));
    printf("\nReverse:%s",strrev(name));
    printf("\nLength:%d",strlen(name));
    printf("\n%s",copy_name);
    printf("\n%s",strcat(copy_name," Garu"));

    return 0;
}
Expected Output:
Enter any Name Original:10 Uppercase:10 Lowercase:10 Reverse:01 Length:2 10 10 Garu
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

29. String Comparison for Password Authentication

Concept: Compares two character sequences lexicographically using strcmp() to validate user credentials against stored passwords.

program_29.c

//Password match example using String Comparision using strcmp()
#include <stdio.h>
int main()
{
    int a,b,c;
    float amount=4500.50;
    printf("Enter a,b,c values"); //prompt message
    scanf("%d",&a); //reading data
    scanf("%d",&b);
    scanf("%d",&c);
    printf("A=%d B=%d C=%d",a,b,c); //out put
    printf("\nAmount=%.2f",amount); //.2f means it shows only 2 decimals
    return 0;
}
Expected Output:
Enter a,b,c valuesA=10 B=20 C=30 Amount=4500.50
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Function and its Types

30. Functions: No Arguments and No Return Value

Concept: Demonstrates modular code organization with independent subroutines that execute self-contained operations without parameters or returns.

program_30.c

#include <stdio.h>
#define PI 3.1416//global declaration 
//No Arguments pass but No Return values
int main()
{
 int n,i;
 printf("Enter n value");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 area();   
 }

    return 0;
}
area()
{
    float r,a;
    printf("\nEnter radius value");
    scanf("%f",&r);
    a=PI*r*r;
    printf("\n%f area is %f",r,a);
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:11:2: error: implicit declaration of function 'area' [-Wimplicit-function-declaration] 11 | area(); | ^~~~ temp_prog.c: At top level: temp_prog.c:16:1: error: return type defaults to 'int' [-Wimplicit-int] 16 | area() | ^~~~
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

31. Functions: Arguments Passed with No Return Value

Concept: Passes parameter values from the caller to a target function to perform computations without returning data.

program_31.c

//2 Arguments pass but No Return value
#include <stdio.h>
#define PI 3.1416//global declaration 
//Arguments pass but No Return values
int main()
{
 float r;
 printf("Enter radius value");
 scanf("%f",&r);
 area(r);
    return 0;
}
area(r)
float r;
{
    float a;
    a=PI*r*r;
    printf("\n%f area is %f",r,a);
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:10:2: error: implicit declaration of function 'area' [-Wimplicit-function-declaration] 10 | area(r); | ^~~~ temp_prog.c: At top level: temp_prog.c:13:1: error: return type defaults to 'int' [-Wimplicit-int] 13 | area(r) | ^~~~ temp_prog.c: In function 'area': temp_prog.c:13:1: warning: old-style function definition [-Wold-style-definition]
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

32. Functions: Parameter Passing by Value

Concept: Illustrates pass-by-value mechanics where local parameter copies ensure the caller's original argument values remain unmodified.

program_32.c

#include <stdio.h>
#define PI 3.1416//global declaration 
//Arguments pass but No Return values
int main()
{
 float r;
 int n,i;
 printf("Enter n value");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 printf("\nEnter radius value");
 scanf("%f",&r);
 area(r);   
 }

    return 0;
}
area(r)
float r;
{
    float a;
    a=PI*r*r;
    printf("\n%f area is %f",r,a);
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:14:2: error: implicit declaration of function 'area' [-Wimplicit-function-declaration] 14 | area(r); | ^~~~ temp_prog.c: At top level: temp_prog.c:19:1: error: return type defaults to 'int' [-Wimplicit-int] 19 | area(r) | ^~~~ temp_prog.c: In function 'area': temp_prog.c:19:1: warning: old-style function definition [-Wold-style-definition]
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

33. Functions: No Arguments with Return Value

Concept: Demonstrates a modular function that gathers internal input, performs calculations, and returns the result to the caller.

program_33.c

//No arguments  and return value
#include <stdio.h>
#define PI 3.1416
int main()
{
    float area,cal_area();
    int n,i;
    printf("Enter n value");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        area=cal_area();
        printf(" area is %f",area);
    }
    return 0;
}

float cal_area()
{
    float a,r;
    printf("\nEnter radius value");
    scanf("%f",&r);
    a=PI*r*r;
    printf("\n%f",r);
    return(a);
}
Expected Output:
Enter n value Enter radius value 20.000000 area is 1256.640015 Enter radius value 30.000000 area is 2827.439941 Enter radius value 5.000000 area is 78.540001 Enter radius value 1.000000 area is 3.141600 Enter radius value 2.000000 area is 12.566400 Enter radius value 3.000000 area is 28.274401 Enter radius value 4.000000 area is 50.265598 Enter radius value 5.000000 area is 78.540001 Enter radius value 100.000000 area is 31416.000000 Enter radius value 0.000000 area is 0.000000
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

34. Passing One-Dimensional Arrays to Functions

Concept: Passes array base pointers to modular functions for reusable array processing, searching, and traversal.

program_34.c

//Functions with one dimensional Array
#include <stdio.h>
#define PI 3.1416
int main()
{
    int a[20],n,read_array(),display_array();
    printf("enter n value");
    scanf("%d",&n);
    read_array(a,n);
    display_array(a,n);
    
    return 0;
}
int read_array(int x[20],int size)
{
  int i;
 for(i=0;i<size;i++)
 {
     printf("\nEnter %d value",i+1);
     scanf("%d",&x[i]);
 }
return 0;
}
int display_array(int x[20],int  size)
{
    int i;
 for(i=0;i<size;i++)
 {
     printf("%2d",x[i]);
 }  
return 0;
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:9:5: error: too many arguments to function 'read_array'; expected 0, have 2 9 | read_array(a,n); | ^~~~~~~~~~ ~ temp_prog.c:6:17: note: declared here 6 | int a[20],n,read_array(),display_array(); | ^~~~~~~~~~ temp_prog.c:10:5: error: too many arguments to function 'display_array'; expected 0, have 2 10 | display_array(a,n); | ^~~~~~~~~~~~~ ~ temp_prog.c:6:30: note: declared here 6 | int a[20],n,read_array(),display_array(); | ^~~~~~~~~~~~~ temp_prog.c: At top level: temp_prog.c:14:5: error: conflicting types for 'read_array'; have 'int(int *, int)' 14 | int read_array(int x[20],int size) | ^~~~~~~~~~ temp_prog.c:6:17: note: previous declaration of 'read_array' with type 'int(void)' 6 | int a[20],n,read_array(),display_array(); | ^~~~~~~~~~ temp_prog.c:24:5: error: conflicting types for 'display_array'; have 'int(int *, int)' 24 | int display_array(int x[20],int size) | ^~~~~~~~~~~~~ temp_prog.c:6:30: note: previous declaration of 'display_array' with type 'int(void)' 6 | int a[20],n,read_array(),display_array(); | ^~~~~~~~~~~~~
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

35. Passing Two-Dimensional Arrays to Functions

Concept: Demonstrates passing multi-dimensional matrix structures to modular functions for structured grid operations.

program_35.c

//Functions with Two dimensional Array
#include <stdio.h>
#define PI 3.1416
int main()
{
    int a[20][20],r,c,read_array(),display_array();
    printf("enter row and column value");
    scanf("%d%d",&r,&c);
    read_array(a,r,c);
    display_array(a,r,c);
    
    return 0;
}
int read_array(int a[20][20],int r,int c)
{
  int i,j;
  printf("\nEnter %dX%d Matrix values",r,c);
 for(i=0;i<r;i++)
 {
     for(j=0;j<c;j++)
     {
         scanf("%d",&a[i][j]);
     }
     
 }
return 0;
}
int display_array(int a[20][20],int  r,int c)
{
    int i,j;
 for(i=0;i<r;i++)
 {
     for(j=0;j<c;j++)
     {
         printf("%3d",a[i][j]);
     }
     printf("\n");
     
 }
return 0;
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:9:5: error: too many arguments to function 'read_array'; expected 0, have 3 9 | read_array(a,r,c); | ^~~~~~~~~~ ~ temp_prog.c:6:23: note: declared here 6 | int a[20][20],r,c,read_array(),display_array(); | ^~~~~~~~~~ temp_prog.c:10:5: error: too many arguments to function 'display_array'; expected 0, have 3 10 | display_array(a,r,c); | ^~~~~~~~~~~~~ ~ temp_prog.c:6:36: note: declared here 6 | int a[20][20],r,c,read_array(),display_array(); | ^~~~~~~~~~~~~ temp_prog.c: At top level: temp_prog.c:14:5: error: conflicting types for 'read_array'; have 'int(int (*)[20], int, int)' 14 | int read_array(int a[20][20],int r,int c) | ^~~~~~~~~~ temp_prog.c:6:23: note: previous declaration of 'read_array' with type 'int(void)' 6 | int a[20][20],r,c,read_array(),display_array(); | ^~~~~~~~~~ temp_prog.c:28:5: error: conflicting types for 'display_array'; have 'int(int (*)[20], int, int)' 28 | int display_array(int a[20][20],int r,int c) | ^~~~~~~~~~~~~ temp_prog.c:6:36: note: previous declaration of 'display_array' with type 'int(void)' 6 | int a[20][20],r,c,read_array(),display_array(); | ^~~~~~~~~~~~~
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Structures

36. Global Structure Declaration

Concept: Defines a user-defined composite data type accessible globally across all functions within the compilation unit.

program_36.c

//Structure using Global Declaration
#include <stdio.h>
// A similar data type of information can be store into single variable is called arrays
// A different data type of elements can be store into a single variable is called structure
//Global Declration
struct Student
{
    int code;
    char name[20];
    char course[11];
};
int main()
{
    //initialization
    struct Student stu={100,"Sreee","C Language"};
    printf("\nCode:%d",stu.code);
    printf("\nName:%s",stu.name);
    printf("\nCourse:%s",stu.course);
    
    return 0;
}
Expected Output:
Code:100 Name:Sreee Course:C Language
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

37. Local Structure Declaration

Concept: Restricts structure definition visibility to local function scope, demonstrating encapsulation in C.

program_37.c

//2 Structures using Local Declration
#include <stdio.h>
int main()
{
    //local declration
    //initialization
struct 
{
    int code;
    char name[20];
    char course[11];
}student={100,"Sreee","C Language"};

    printf("\nCode:%d",student.code);
    printf("\nName:%s",student.name);
    printf("\nCourse:%s",student.course);
    
    return 0;
}
Expected Output:
Code:100 Name:Sreee Course:C Language
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

38. Multiple Structure Instances

Concept: Instantiates and initializes multiple distinct object records from a single unified structure blueprint.

program_38.c

//Create multiple instances using Structures
#include <stdio.h>
struct Student
{
    int code;
    char name[20];
    char course[11];
};

int main()
{
    struct Student stu1,stu2;
    printf("enter stu1 code name course");
    scanf("%d%s%s",&stu1.code,stu1.name,stu1.course);
    printf("enter stu2 code name course");
    scanf("%d%s%s",&stu2.code,stu2.name,stu2.course);
    printf("\nStudent 1 Details:");
    printf("\nCode:%d",stu1.code);
    printf("\nName:%s",stu1.name);
    printf("\nCourse:%s",stu1.course);
    printf("\nStudent 2 Details:");
    printf("\nCode:%d",stu2.code);
    printf("\nName:%s",stu2.name);
    printf("\nCourse:%s",stu2.course);
    
    return 0;
}
Expected Output:
enter stu1 code name courseenter stu2 code name course Student 1 Details: Code:10 Name:20 Course:30 Student 2 Details: Code:5 Name:1 Course:2
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

39. Array of Structures

Concept: Combines arrays and user-defined structures to model, store, and process collections of employee or student entities in contiguous memory.

program_39.c

//Structures with Arrays
#include <stdio.h>
//structures with arrays
struct Student
{
    int code;
    char name[20];
    char course[11];
};

int main()
{
    struct Student student[20];
    int n,i;
    printf("Enter how many memeber data you want to enter");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    printf("enter stu%d code name course",i+1);
    scanf("%d%s%s",&student[i].code,student[i].name,student[i].course); 
    }
    printf("\nCode Name               Course");
    for(i=0;i<n;i++)
    {
    printf("\n%-5d%-20s%-11s",student[i].code,student[i].name,student[i].course); 
    }
    
    return 0;
}
Expected Output:
Enter how many memeber data you want to enterenter stu1 code name courseenter stu2 code name courseenter stu3 code name courseenter stu4 code name courseenter stu5 code name courseenter stu6 code name courseenter stu7 code name courseenter stu8 code name courseenter stu9 code name courseenter stu10 code name course Code Name Course 20 30 5 1 2 3 4 5 100 32758 ö 1 0 R e 6357064r m 6029396t e 0 0
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

40. Nested Structures (Substructures)

Concept: Demonstrates embedding one structure definition inside another to represent hierarchical real-world data relationships.

program_40.c

//structures with Substructures
struct Student
{
    int code;
    char name[20];
    char course[11];
    struct 
    {
        char area[20];
        char city[20];
        char state[20];
    }address;
};

int main()
{
    struct Student student;
    printf("Enter code name course");
    scanf("%d%s%s",&student.code,student.name,student.course);
    printf("Enter area,city,state");
    scanf("%s%s%s",student.address.area,student.address.city,student.address.state);
    printf("\nCode:%d",student.code);
    printf("\nName:%s",student.name);
    printf("\nCourse:%s",student.course);
    printf("\nArea:%s",student.address.area);
    printf("\nCity:%s",student.address.city);
    printf("\nState:%s",student.address.state);

    return 0;
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:18:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 18 | printf("Enter code name course"); | ^~~~~~ temp_prog.c:1:1: note: include '<stdio.h>' or provide a declaration of 'printf' +++ |+#include <stdio.h> 1 | //structures with Substructures temp_prog.c:18:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] 18 | printf("Enter code name course"); | ^~~~~~ temp_prog.c:18:5: note: include '<stdio.h>' or provide a declaration of 'printf' temp_prog.c:19:5: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 19 | scanf("%d%s%s",&student.code,student.name,student.course); | ^~~~~ temp_prog.c:19:5: note: include '<stdio.h>' or provide a declaration of 'scanf' temp_prog.c:19:5: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] temp_prog.c:19:5: note: include '<stdio.h>' or provide a declaration of 'scanf'
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

41. Passing Structures to Functions

Concept: Demonstrates passing complete structured entity instances into modular functions for clean display and business processing.

program_41.c

//Structures Using Functions
#include <stdio.h>

#include 
struct Employee
{
    int code;
    char name[20];
    float salary;
};
int main()
{
    struct Employee emp,updateSal();
    printf("Enter employee Code Name Salary");
    scanf("%d%s%f",&emp.code,emp.name,&emp.salary);
    printf("\nCode;%d\nName:%s\nSalary:%.2f",emp.code,emp.name,emp.salary);
    emp=updateSal(emp);
    printf("\nCode;%d\nName:%s\nSalary:%.2f",emp.code,emp.name,emp.salary);

    return 0;
}
struct Employee updateSal(temp_emp)
struct Employee temp_emp;
{
    float salary;
    printf("How much salary you want add ");
    scanf("%f",&salary);
    temp_emp.salary=temp_emp.salary+salary;
    return (temp_emp);
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:17:9: error: too many arguments to function 'updateSal'; expected 0, have 1 17 | emp=updateSal(emp); | ^~~~~~~~~ ~~~ temp_prog.c:13:25: note: declared here 13 | struct Employee emp,updateSal(); | ^~~~~~~~~ temp_prog.c: In function 'updateSal': temp_prog.c:13:25: warning: old-style function definition [-Wold-style-definition] temp_prog.c:24:1: error: number of arguments doesn't match prototype 24 | { | ^ temp_prog.c:13:25: error: prototype declaration 13 | struct Employee emp,updateSal(); | ^~~~~~~~~
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Pointers

42. Pointer Fundamentals: Address & Dereferencing

Concept: Introduces memory addresses, the address-of operator (&), and the dereferencing operator (*) to manipulate memory directly.

program_42.c

//Pointers Basic Example
#include <stdio.h>
int main()
{
int a,b,*p,*q;
printf("Enter a,b values");
scanf("%d%d",&a,&b);
printf("\nA=%d B=%d",a,b);
p=&a;
q=&b;
printf("\nA=%d B=%d ",p,q);
printf("\nP=%d Q=%d ",&p,&q);
printf("\nA=%d B=%d ",*p,*q);
printf("\nA=%d B=%d ",&a,&b);
printf("\nP=%d Q=%d ",p,q);
   return 0;
}
Expected Output:
Enter a,b values A=10 B=20 A=1138753148 B=1138753144 P=1138753136 Q=1138753128 A=10 B=20 A=1138753148 B=1138753144 P=1138753148 Q=1138753144
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

43. Pointer Arithmetic & Memory Offsets

Concept: Demonstrates pointer incrementation and memory offsetting scaled according to the underlying data type's byte size.

program_43.c

//Pointers Artithmatic
#include <stdio.h>
int main()
{
int a,b,*p,*q;
printf("Enter a,b values");
scanf("%d%d",&a,&b);
p=&a;
q=&b;
printf("\nA+B=%d",(*p)+(*q));
printf("\nA-B=%d",(*p)-(*q));
printf("\nA*B=%d",(*p)*(*q));
printf("\nA/B=%d",(*p)/(*q));
printf("\nA mod B=%d",(*p)%(*q));
}
Expected Output:
Enter a,b values A+B=30 A-B=-10 A*B=200 A/B=0 A mod B=10
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

44. Pointers to Structures (Arrow Operator)

Concept: Uses structure pointer references and the arrow member selection operator (->) to access entity fields in heap or stack memory.

program_44.c

//Pointers Using Structures
#include <stdio.h>
int main()
{
struct 
{
    int code;
    char name[20];
}*emp;
printf("Enter Code Name");
scanf("%d%s",&emp->code,emp->name);
printf("\nCode:%d\nName:%s",emp->code,emp->name);
return 0;
}
Expected Output:
Enter Code Name Code:10 Name:20
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

45. Pointers with One-Dimensional Arrays

Concept: Demonstrates array name decay to base element pointers, enabling efficient pointer arithmetic for array element traversal.

program_45.c

//Pointers One dimensional
#include <stdio.h>
int main()
{
int *a,n,i;
printf("Enter n value");
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",(a+i));
}
printf("\nThe Numbers are ");
for(i=0;i<n;i++)
{
    printf("%3d",*(a+i));
}
return 0;
}
Expected Output:
Enter n value The Numbers are 20 30 5 1 2 3 4 5100 0
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

46. Pointers with Two-Dimensional Arrays

Concept: Explores multi-level pointer arithmetic for row and column address resolution in two-dimensional matrices.

program_46.c

//Pointers Using Two Dimensional Array
#include <stdio.h>

int main()
{
int *a[10][10],r,c,i,j;
printf("Enter r,c value");
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
    for(j=0;j<c;j++)
    {
      scanf("%d",*(a+i)+j);  
    }
    
}
printf("\nThe Numbers are\n");
for(i=0;i<r;i++)
{
     for(j=0;j<c;j++)
    {
      printf("%3d",*(*(a+i)+j));  
    }
    printf("\n");
}
return 0;
}
Expected Output:
Enter r,c value The Numbers are 30 5 1 2 3 4 5100538 0-579137536-5791416321288192409616777216-579141632736876288-2125255760 0 -579137536-5791416321288192409616777216-579141632736876288-2125255760 0-2125261824-579112888-579137520-579137520-72284936-1116624624-579112896 0 1 4 -2125261824-579112888-579137520-579137520-72284936-1116624624-579112896 0 1 4-579141632147456167772165505106-153301940044565406488169635706468813807274582 -579141632147456167772165505106-15330194004456540648816963570646881380727458266192454784212661925273401273014759101 0 0 0 0 66192454784212661925273401273014759101 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0-1123249387-2125255760 0 0-1122002752 0 0 0 0 0-1123249387-2125255760 0 0-1122002752 1-1123248066-1533018912-1123249387-2125255760 0 0-1122002752 1-1123248066 1-1123248066-1533018912-1123249387-2125255760 0 0-1122002752 1-1123248066-1533018848-1533018848-1122002752-1533018848 14-1122790617-579112896 1-1122001376-1533018848 -1533018848-1533018848-1122002752-1533018848 14-1122790617-579112896 1-1122001376-1533018848-1533018832 11 1-579137286 2 2-1122001376-579135968-1533018772 0
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Files

47. File Handling: Writing Character by Character

Concept: Demonstrates creating disk files and writing text byte-by-byte using file pointers and fputc().

program_47.c

//1 Create File (Chracter by Character)
#include <stdio.h>
FILE *fp;
main()
{
char fname[11],c;
clrscr();
printf("\nEnter your filename");
scanf("%s",fname);
fp=fopen(fname,"w");
while((c=getchar())!=EOF)
{
putc(fp,c);
}
fclose(fp);
printf("\nFile Successfully Created");
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c:4:1: error: return type defaults to 'int' [-Wimplicit-int] 4 | main() | ^~~~ temp_prog.c: In function 'main': temp_prog.c:7:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 7 | clrscr(); | ^~~~~~ temp_prog.c:13:6: error: passing argument 1 of 'putc' makes integer from pointer without a cast [-Wint-conversion] 13 | putc(fp,c); | ^~ | | | FILE * {aka struct _iobuf *} In file included from temp_prog.c:2: C:/msys64/ucrt64/include/stdio.h:621:24: note: expected 'int' but argument is of type 'FILE *' {aka 'struct _iobuf *'} 621 | int __cdecl putc(int _Ch,FILE *_File); | ~~~~^~~ temp_prog.c:13:9: error: passing argument 2 of 'putc' makes pointer from integer without a cast [-Wint-conversion] 13 | putc(fp,c); | ^ | | | char C:/msys64/ucrt64/include/stdio.h:621:34: note: expected 'FILE *' {aka 'struct _iobuf *'} but argument is of type 'char' 621 | int __cdecl putc(int _Ch,FILE *_File); | ~~~~~~^~~~~ temp_prog.c:17:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 17 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

48. File Handling: Reading Character by Character

Concept: Reads characters sequentially from a disk file until encountering the EOF (End Of File) marker using fgetc().

program_48.c

// Read File Character by Character
#include <stdio.h>
FILE *fp;
main()
{
char fname[11],c;
clrscr();
printf("\nEnter your filename");
scanf("%s",fname);
fp=fopen(fname,"r");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
fclose(fp);
printf("\nFile Successfully Appended");
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c:4:1: error: return type defaults to 'int' [-Wimplicit-int] 4 | main() | ^~~~ temp_prog.c: In function 'main': temp_prog.c:7:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 7 | clrscr(); | ^~~~~~ temp_prog.c:17:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 17 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

49. File Handling: Appending Character by Character

Concept: Demonstrates opening disk files in append mode ("a") to add new character data without overwriting existing content.

program_49.c

//Append File Character by Character
#include <stdio.h>
FILE *fp;
main()
{
char fname[11],c;
clrscr();
printf("\nEnter your filename");
scanf("%s",fname);
fp=fopen(fname,"a");
while((c=getchar())!=EOF)
{
putc(fp,c);
}
fclose(fp);
printf("\nFile Successfully Created");
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c:4:1: error: return type defaults to 'int' [-Wimplicit-int] 4 | main() | ^~~~ temp_prog.c: In function 'main': temp_prog.c:7:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 7 | clrscr(); | ^~~~~~ temp_prog.c:13:6: error: passing argument 1 of 'putc' makes integer from pointer without a cast [-Wint-conversion] 13 | putc(fp,c); | ^~ | | | FILE * {aka struct _iobuf *} In file included from temp_prog.c:2: C:/msys64/ucrt64/include/stdio.h:621:24: note: expected 'int' but argument is of type 'FILE *' {aka 'struct _iobuf *'} 621 | int __cdecl putc(int _Ch,FILE *_File); | ~~~~^~~ temp_prog.c:13:9: error: passing argument 2 of 'putc' makes pointer from integer without a cast [-Wint-conversion] 13 | putc(fp,c); | ^ | | | char C:/msys64/ucrt64/include/stdio.h:621:34: note: expected 'FILE *' {aka 'struct _iobuf *'} but argument is of type 'char' 621 | int __cdecl putc(int _Ch,FILE *_File); | ~~~~~~^~~~~ temp_prog.c:17:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 17 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

50. File Handling: Writing Structure Records with fprintf()

Concept: Formats and persists structured employee records to disk storage using fprintf() for persistent record keeping.

program_50.c

//Create a file using Structure Based Data
#include <stdio.h>
FILE *fp;
struct Employee
{
int code;
char name[20];
long int salary;
}
main()
{
struct Employee emp;
char fname[11];
clrscr();
printf("Enter your file name");
scanf("%s",fname);
fp=fopen(fname,"w");
do
{
printf("\nEnter Code");
scanf("%d",&emp.code);
if(emp.code>0)
{
printf("\nEnter Name and Salary");
scanf("%s",emp.name);
scanf("%ld",&emp.salary);
fprintf(fp,"\n%-5d%-20s%-10ld",emp.code,emp.name,emp.salary);
}
}while(emp.code>0);
fclose(fp);
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:14:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 14 | clrscr(); | ^~~~~~ temp_prog.c:31:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 31 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

51. File Handling: Reading Structure Records with fscanf()

Concept: Parses formatted structured data records from disk storage back into memory instances using fscanf().

program_51.c

//Create a file using Structure Based Data
#include <stdio.h>
FILE *fp;
struct Employee
{
int code;
char name[20];
long int salary;
}
main()
{
struct Employee emp;
char fname[11];
clrscr();
printf("Enter your file name");
scanf("%s",fname);
fp=fopen(fname,"r");
while((fscanf(fp,"%d%s%ld",&emp.code,emp.name,&emp.salary))!=EOF)
{
printf("\n%-5d%-20s%-10ld",emp.code,emp.name,emp.salary);
}
fclose(fp);
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:14:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 14 | clrscr(); | ^~~~~~ temp_prog.c:23:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 23 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

52. File Handling: Appending Records to Existing File

Concept: Demonstrates opening structured database files in append mode to add new employee records to persistent storage.

program_52.c

//2 Data Input and output Example
#include <stdio.h>
FILE *fp;
struct Employee
{
int code;
char name[20];
long int salary;
}
main()
{
struct Employee emp;
char fname[11];
clrscr();
printf("Enter your Existing file name");
scanf("%s",fname);
fp=fopen(fname,"r");
do
{
printf("\nEnter Code");
scanf("%d",&emp.code);
if(emp.code>0)
{
printf("\nEnter Name and Salary");
scanf("%s",emp.name);
scanf("%ld",&emp.salary);
fprintf(fp,"\n%-5d%-20s%-10ld",emp.code,emp.name,emp.salary);
}
}while(emp.code>0);
fclose(fp);
getch();
}
Expected Output:
Compilation Warning/Error: temp_prog.c: In function 'main': temp_prog.c:14:1: error: implicit declaration of function 'clrscr' [-Wimplicit-function-declaration] 14 | clrscr(); | ^~~~~~ temp_prog.c:31:1: error: implicit declaration of function 'getch'; did you mean 'getc'? [-Wimplicit-function-declaration] 31 | getch(); | ^~~~~ | getc
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

'C' Language Interview Question and Answers

53. Counting Digits in an Integer

Concept: Uses repeated integer division by 10 within a loop to calculate the total number of digits in an input number.

program_53.c

//Count digits in a numbers
#include <stdio.h>
int main()
{
    int n,count=0;
    printf("etner any number");
    scanf("%d",&n);
    while(n!=0)
    {
       count++;
        n=n/10;
    }
    printf("Length of Above Number :%d" ,count);
    
    return 0;
}
Expected Output:
etner any numberLength of Above Number :2
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

54. Factorial Calculation using Recursion

Concept: Demonstrates recursive function execution with a definitive base condition to calculate the factorial of a positive integer.

program_54.c

//Factorial Using Recursion
#include <stdio.h>
int fact(int x)
{
    if(x==0)
    {
        return 1;
    }
    printf("\n%d",x);
    return x*fact(x-1);
}
int main()
{
  int n;
  printf("Enter n value");
  scanf("%d",&n);
  printf("\n%dact is %d",n,fact(n));
    
    return 0;
}
Expected Output:
Enter n value 10 9 8 7 6 5 4 3 2 1 10act is 3628800
Complexity Analysis
  • Time Complexity: O(1) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

55. Fibonacci Series Generation using For Loop

Concept: Computes the Fibonacci sequence iteratively by maintaining tracking variables for preceding adjacent sequence terms.

program_55.c

#include <stdio.h>
/*
Fibonacci using Loop
F(0)=0
F(1)=1
F(n)=F(n-1)+F(n-2)
*/

int main()
{
  int n,a=0,b=1,c,i;
  printf("Enter n value");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
      printf("%d ",a);
      c=a+b;
      a=b;
      b=c;
      
  }

    return 0;
}
Expected Output:
Enter n value0 1 1 2 3 5 8 13 21 34
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

56. Finding the Second Largest Element in an Array

Concept: Traverses an array in a single pass to determine both the primary maximum and second-highest values simultaneously.

program_56.c

//Find Second Large Number
#include <stdio.h>
int main()
{
    int a[100],n,max,smax,i;
    printf("Enter n value");
    scanf("%d",&n);
    printf("Enter %d Numbers",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    max=smax=-9999;
    for(i=0;i<n;i++)
    {
        if(a[i]>max)
        {
            smax=max;
            max=a[i];
        }
        else if(a[i]>smax && a[i]!=max)
        {
            smax=a[i];
        }
    }
    printf("Second Largest Number %d",smax);
    return 0;
}
Expected Output:
Enter n valueEnter 10 NumbersSecond Largest Number 30
Complexity Analysis
  • Time Complexity: O(N^2) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

57. Prime Number Check using Divisibility Test

Concept: Tests integer primality by verifying whether the number has positive integer divisors beyond 1 and itself.

program_57.c

//Prime Number Check
#include <stdio.h>
int main()
{
    int n,count=0,i;
    printf("etner any number");
    scanf("%d",&n);
   for(i=2;i<n;i++)
    {
       if(n%i==0)
       {
           count++;
       }
    }
    if(count==0)
    {
      printf("Prime")  ;
    }
    else
    {
        printf("Not Prime");
    }
    
    return 0;
}
Expected Output:
etner any numberNot Prime
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

58. Reversing an Integer Number

Concept: Extracts digits using modulus % 10 and reconstructs the reversed number mathematically using reversed = reversed * 10 + digit.

program_58.c

//Reverse Number
#include <stdio.h>
int main()
{
    int n,rev=0,r;
    printf("etner any number");
    scanf("%d",&n);
    while(n!=0)
    {
        r=n%10;
        rev=(rev*10)+r;
        n=n/10;
    }
    printf("Reverse of Above Number :%d" ,rev);
    
    return 0;
}
Expected Output:
etner any numberReverse of Above Number :1
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

59. String Length Calculation without Library Function

Concept: Traverses a character array sequentially until encountering the null-terminator byte () to compute string length.

program_59.c

//String length with out using function
#include <stdio.h>

int main()
{
   char name[20];
   int len=0;
   printf("Enter any String ");
   scanf("%s",name);
   while(name[len]!='\0')
   {
       len++;
   }
   printf("\nString Length is %d",len);
    return 0;
}
Expected Output:
Enter any String String Length is 2
Complexity Analysis
  • Time Complexity: O(N) - Iterative operations scale accordingly with input size.
  • Space Complexity: O(1) - Allocates a fixed amount of memory regardless of input scale.

Conclusion & Next Steps

This concludes our list of essential C programs. By practicing these snippets, you enhance your understanding of memory management, pointers, and procedural programming. C forms the foundation of many modern languages, and mastering it will make you a stronger overall software engineer.