< / Popular C Programs >

Testing Phase

Determine alphabet or number Program # 1

To determine whether an input value is an alphabet or number

              
  // Check if Character is an Alphabet or not

  #include <stdio.h>
  int main() {
    // 65 - 90 A - Z ----- ASCII CODES 
    // 97 - 122 a - z
    // 48 - 57 0 - 9 
    char a;
    printf("Please Enter a character : \n");
    scanf("%c",&a);
    
    if((a >= 65 && a <= 90) || (a >= 97 && a<= 122))   
    {
      printf("It's an alphabet! \n");
    }
    else if(a >= 48 && a <= 57){
      printf("It's a number! \n");
    }
    else{
      printf("Error! \n");
    }
    
    return 0;
  }
              
          

Calculate the area of triangle and square Program # 2

Calculating the area of triangle and square by taking input value based on the user choice.

              
  // Find Area of Triangle & Square

  #include <stdio.h>
  #include <math.h>
  int main(){
    // S, s OR T, t
    char input;
    float areaOfSquare, areaOfTriangle, s, b, h;
    printf("Choose to Calculate the Area of : \n");
    printf("(S) for Square : ");
    printf("(T) for Triangle : ");
    scanf("%c",&input);
    
    if(input == 83 || input == 115){
      printf("Enter value of s : ");
      scanf("%f",&s); 
      areaOfSquare = pow(s,2);
      printf("Area of Square is %.2f : ",areaOfSquare);
    }
    else if(input == 84 || input == 116){
      printf("Enter value of height : ");
      scanf("%f",&h); 
      printf("Enter value of base : ");
      scanf("%f",&b); 
      areaOfTriangle = 0.5 * b * h;
      printf("Area of Triangle is %.2f : ",areaOfTriangle);   
    }
    else{
      printf("Error");
    }
    return 0;
  }
              
          

Printing A - Z alphabets Program # 3

Simply printing A - Z alphabets

              
  //Display Characters from A to Z Using Loop   

  #include <stdio.h>
  int main() {
    
    // ASCII will be helpful here
    char a = 65;
    for(; a <= 90; a++){
      printf("%c \t",a);
    }
    
    return 0;	
  }
              
          

Generate multiplication table Program # 4

The aim is to print a multiplication table based on the integer value given by the user

              
  //Displaying multiplication table  

  #include <stdio.h>
  int main() {
    int n;
    printf("Enter a positive integer : ");  
    scanf("%d",&n);
    
    for(int i = 1; i <= 10; i++){
      printf("%d x %d = %d\n",n,i,n*i);
    }

    return 0;	
}
              
          

Check Even / Odd number Program # 5

Check if the given value is Even or Odd

              
  // Determining Even / Odd Numbers

  #include 
  int main(){
    
    int num;
    
    printf("Enter any Number : \n");
    scanf("%d",&num);
    
    if(num % 2 == 0 && num != 0){
      printf("It's an Even Number! \n");
    }
    else if(num % 2 == 1){
      printf("It's an Odd Number! \n");
    }
    else{
      printf("I think you entered Zero! \n");  
    }
    
    return 0;
  }
              
          

Find factorial of a number Program # 6

Finding the factorial of a number entered by the user

              
 // Find the Factorial of a number 

  #include 
  int main() {
      int n, i;
      unsigned long long fact = 1;
      printf("Enter an integer: ");
      scanf("%d", &n);

      if (n < 0)
          printf("Error! Factorial of a negative number doesn't exist.");  
      else {
          for (i = 1; i <= n; i++) {
              fact *= i;
          }
          printf("Factorial of %d = %llu", n, fact);
      }

      return 0;
  }

              
          

Find factors of a number Program # 7

Finding the factors of a number given by the user

              
  // Factors of a Number
  #include 
  int main() {
    
    int n;
    
    printf("Enter a number to find factors of : ");  
    scanf("%d",&n);
    
    for(int i = 1; i <= n; i++){
      if(n % i == 0){
        printf(" %d \t",i);
      }
    }

    getch();
    return 0;
}
              
          

Finding remainder Program # 8

Finding remainder and qoutient by taking values from the user

              
 // Finding Remainder & Quotient

  #include 
  int main(){
    int divisor, dividend, remainder, quotient;
    
    printf("Enter a dividend: \n");
    scanf("%d", ÷nd);
    
    printf("\n");

    printf("Enter a divisor: \n");
    scanf("%d", &divisor);
    
    remainder = dividend % divisor;
    quotient = dividend / divisor;
    
    printf("Remainder is : %d \n Quotient is : %d",remainder, quotient);   
    
    return 0;
  }
              
          

Finding size of datatypes Program # 9

Finding sizes of different data types at once.

              
  // Find the Size of int, float, double and char

  #include 
  #include 
  int main() {
    
    printf("Size of int is : %zu bytes \n",sizeof(int));
    printf("Size of float is : %zu bytes \n",sizeof(float));
    printf("Size of double is : %zu bytes \n",sizeof(double));
    printf("Size of char is : %zu bytes \n",sizeof(char));
    
    return 0;
  }
              
          

Finding the largest number Program # 10

Finding the largest number among three entered number

              
 // Finding the largest number among 3 numbers

  #include 
  int main() {
    
    int a, b, c;
    
    printf("Enter First Number : \n");
    scanf("%d",&a);
    
    printf("Enter Second Number : \n");
    scanf("%d",&b);
    
    printf("Enter Third Number : \n");
    scanf("%d",&c);
    
    if(a > b && a > c){
      printf("%d is the largest Number! \n",a);  
    }
    else if(b > a && b > c){
      printf("%d is the largest Number! \n",b);
    }
    else if(c > a && c > b){
      printf("%d is the largest Number! \n",c);
    }
    else {
      printf("Error \n");
    }
    
    return 0;
  }