Blog

  • C program to find factorial of a number using Ternary operator with Recursion

    Recursion refers to the function calling itself directly or in a cycle.

    Before we begin, you should have the knowledge of following in C Programming:

    #include <stdio.h>
    
    int factorial(int n)
    {
      // using ternary operator with recursion
      return (n == 1 || n == 0) ? 1 : n* factorial(n - 1);
    }
    
    int main()
    {
      int num, result;
    
      //taking Inputs
      printf("Enter the number to find factorial: ");
      scanf("%d", &num);
    
      //function call and display the result
      result = factorial(num);
      printf("Factorial of %d is: %d\n", num, result);
      getch();
      return 0;
    }

    This C program calculates the factorial of a given number using recursion and the ternary operator. Here’s a brief explanation:

    1. Function Definition: factorial(int n)
      • This function calculates the factorial of a number n.
      • It uses a ternary operator (? :) to check if n is 1 or 0. If true, it returns 1; otherwise, it recursively calls itself with the argument n - 1 multiplied by n.
    2. Main Function: main()
      • The main function begins the execution of the program.
      • It declares two variables: num for user input and result to store the factorial.
      • The user is prompted to enter a number, which is then stored in the variable num.
      • The factorial function is called with num as an argument, and the result is stored in the result variable.
      • The program prints the factorial result.
    3. Usage of getch():
      • The getch() function is used to hold the console window open until a key is pressed. Note that this function is not standard and may not be available on all systems.
    4. Output:
      • The program outputs the calculated factorial for the given input.
    5. Termination:
      • The program returns 0, indicating successful execution.

  • C Program to Add Two Numbers Using Call by Reference

    The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through the topic below.

    #include <stdio.h>
    
    //user-defined function
    float addFunc(float *a, float *b)
    {
      float sum;
    
      sum = *a + *b;
    
      return sum;
    }
    
    int main()
    {
      float num1, num2, result;
    
      printf("Enter the first number: ");
      scanf("%f", &num1);
    
      printf("Enter the Second number: ");
      scanf("%f", &num2);
    
      result = addFunc(&num1, &num2);
    
      printf("Sum of the result: %f", result);
    
      return 0;
    }

    Output:

    Enter the first number: 15.5
    Enter the Second number: 20.5
    Sum of the result: 36.000000


    This is a simple C program that demonstrates the use of a user-defined function to add two floating-point numbers. Let’s break down the code:

    Function Declaration:

    float addFunc(float *a, float *b)
    • This line declares a function named addFunc that takes two float pointers (a and b) as parameters and returns a float value.

    Function Definition:

    { float sum; sum = *a + *b; return sum; }
    • Inside the addFunc function, it calculates the sum of the values pointed to by a and b and returns the result.

    Main Function:

    int main()
    {
        // Variable declaration
        float num1, num2, result;
    
        // Input from user
        printf("Enter the first number: ");
        scanf("%f", &num1);
    
        printf("Enter the Second number: ");
        scanf("%f", &num2);
    
        // Function call
        result = addFunc(&num1, &num2);
    
        // Output
        printf("Sum of the result: %f", result);
    
        return 0;
    }
    • The main function is the entry point of the program.
    • It declares three float variables num1, num2, and result.
    • It takes user input for num1 and num2 using scanf.
    • Calls the addFunc function, passing the addresses of num1 and num2.
    • Prints the result.

    Execution:

    • The program prompts the user to enter two floating-point numbers.
    • It then calculates the sum of these numbers using the addFunc function.
    • Finally, it prints the result to the console.

    So, if the user enters, for example, 5.3 and 2.7, the program would output:

    Enter the first number: 5.3
    Enter the Second number: 2.7
    Sum of the result: 8.000000

  • Казино Вавада отзывы пользователей и функции платформы



    Казино Вавада отзывы игроков и функционал платформы


    Казино Вавада отзывы пользователей и функции платформы

    Изучение платформы, подобной вавада казино, может быть интересным с учетом мнений игроков. Основные аспекты, о которых стоит упомянуть, включают качество пользовательского интерфейса и скорость обслуживания клиентов. Удобная навигация по сайту, а также быстрая реакция службы поддержки – важные факторы для комфортного времяпрепровождения.

    Ассортимент игр также был высоко оценен. Разнообразие от классических автоматов до более современных решений позволяет каждому найти что-то по душе. Этот аспект дает возможность не только насладиться игрой, но и исследовать новые форматы. С учетом этого, платформа выглядит как привлекательная альтернатива для людей, желающих испытать удачу в увлекательных развлечениях.

    Анализ отзывов игроков о работе казино Вавада

    Поразительно, но значительное количество игроков положительно отзывается о разнообразии игр. Особый акцент делается на качество разработчиков, которые обеспечивают стабильность и увлекательность. Если вам нравятся слоты или настольные игры, обязательно стоит попробовать варианты от известных брендов.

    Каждый отмечает качество поддержки client support. Быстрый ответ на запросы и наличие разных способов связи делают процесс проще. Важен и уровень помощи, предоставляемой операторами. Некоторые пользователи подчеркивают, что им удалось получить решение проблемы в считанные минуты.

    Не забудьте ознакомиться с полными условиями участия. Многие комментируют наличие прозрачных правил и подробностей, это касается как бонусов, так и акций. Четкая информация о ставках и правилах поведения помогает предотвратить недопонимания и создает доверие в сообществе, разделяющем интерес к азартным играм.

    Функциональные возможности платформы Вавада: что предлагает казино

    Эта игровая площадка радует своих пользователей множеством доступных развлечений. Выбор азартных игр включает слоты, настольные и карточные игры. Регулярно обновляемый ассортимент поддерживает интерес и привлекает внимание. Программное обеспечение от известных провайдеров гарантирует высокое качество и интересный игровой процесс.

    На сайте присутствует адаптивная версия, которая позволяет комфортно играть как на компьютере, так и на мобильных устройствах. Интерфейс интуитивно понятен, благодаря чему даже новички смогут быстро освоиться. Искренне рекомендуем использовать мобильное приложение для удобства доступа и отсутствия ограничений по времени.

    • Бонусы: Альтернативные акции и приветственные предложения делают игру более выгодной.
    • Турниры: Регулярные соревнования поднимают уровень адреналина и предлагают крупные призы.

    Поддержка клиентов работает круглосуточно, что обеспечивает оперативное решение возникающих вопросов. Специализированные консультанты доступны через чат или по электронной почте, что добавляет позитивный опыт пользователям. Каждое новое обновление платформы направлено на улучшение пользовательского опыта, что делает пребывание здесь не только развлекательным, но и комфортным.

    Преимущества и недостатки использования казино Вавада по мнению пользователей

    Интуитивно понятный интерфейс – значительное достоинство. Пользователи подчеркивают, что с навигацией по сайту не возникло никаких странностей. Играть или искать нужные разделы можно без лишних затруднений. Это особенно оценили новички, для которых важна простота использования.

    Клиентская поддержка – еще один аспект, о котором часто упоминают. Она действительно работает круглосуточно, и многие пользователи отмечают оперативность ответа на запросы. Наличие нескольких каналов связи, включая чат и электронную почту, позволяет выбрать наиболее удобный способ общения.

    Среди недостатков можно выделить отсутствие мобильного приложения. Несмотря на наличие адаптивной версии сайта, многие предпочли бы установить приложение для быстрого доступа. Это создает некоторый дискомфорт для пользователей, которые хотят играть в любое время и в любом месте.

    Преимущества Недостатки
    Бонус при первом депозите Отсутствие мобильного приложения
    Интуитивно понятный интерфейс Ограниченное количество платежных систем
    Круглосуточная поддержка

    Не стоит игнорировать разнообразие игр. Здесь представлено множество популярных слот-машин и настольных развлечений, что позволяет выбрать что-то по вкусу для каждого. Однако некоторые пользователи требуют более актуальных новинок, которые пока не успели добавить на сайт.

    Следующий момент – это безопасность. Платформа использует современные технологии шифрования, что добавляет уверенности в защите данных. Тем не менее, некоторые пользователи обращают внимание на необходимость верификации, которая может занять время.

    Итак, плюсы и минусы также зависят от личных предпочтений. Убедитесь, что вам подходят условия и функционал перед началом игры, чтобы избежать неприятных ситуаций. Заранее изучите все детали, прежде чем погружаться в предложенные возможности.


  • Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

    In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will get output as ab,cd,ef,g


    Javascript and Python program to concatenate the string element in an array with its preceding string element.

    Javascript:

    const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'];
    let result = [];
    
    for(let i=0; i <= arr.length-1; i = i+2){
            let temp = arr[i] + (arr[i+1] ? arr[i+1] : "");
            result.push(temp)
    }
    print(result);

    Output:

    ab, cd, ef, g


    Python:

    arr = ['a', 'b', 'c', 'd', 'e'];
    result = [];
    i=0
    length = len(arr)
    
    while i <= length-1:
        t=""
        try:
            t=arr[i+1]
        except IndexError:
            t=""
        temp = arr[i] + t
        result.append(temp)
        i += 2
        
    print(result)

    Output:

    ['ab', 'cd', 'ef', 'g']


  • String Pattern Programs in C

    In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C.

    C Pyramid String Pattern: 1

    Enter the string: SIMPLE2CODE
    Enter the no. of rows: 8
    S
    I M
    P L E
    2 C O D
    E S I M P
    L E 2 C O D
    E S I M P L E
    2 C O D E S I M

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       char str[20];
       int rows, a = 0;
    
       printf("Enter the string: ");
       scanf("%[^\n]", str);
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (int i = 0; i <= rows - 1; i++)
       {
          for (int j = 0; j <= rows - i; j++)
             printf(" ");
    
          for (int k = 0; k <= i; k++)
          {
             printf("%2c", str[a++]);
    
             if (str[a] == '\0')
                a = 0;
          }
    
          printf("\n");	// for new line
       }
    }

    Mirrored half diamond string pattern in C: 2

    Enter the string: SIMPLE2CODE
    S
    SI
    SIM
    SIMP
    SIMPL
    SIMPLE
    SIMPLE2
    SIMPLE2C
    SIMPLE2CO
    SIMPLE2COD
    SIMPLE2CODE
    IMPLE2CODE
    MPLE2CODE
    PLE2CODE
    LE2CODE
    E2CODE
    2CODE
    CODE
    ODE
    DE
    E

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       char str[20];
       int strLength;
    
       printf("Enter the string: ");
       scanf("%[^\n]", str);
    
      	// count the no. of characters
       for (strLength = 0; str[strLength] != '\0'; strLength++);
    
      	// for first half
       for (int i = 0; i < strLength; i++)
       {
          for (int j = 0; j < strLength - i - 1; j++)
             printf(" ");	// space
    
          for (int j = 0; j <= i; j++)
             printf("%c", str[j]);
    
          printf("\n");	// for a new line
       }
    
      	// for second half
       for (int i = 1; i < strLength; i++)
       {
          for (int j = 0; j < i; j++)
             printf(" ");	// space
    
          for (int j = i; j < strLength; j++)
             printf("%c", str[j]);
    
          printf("\n");	// for a new line
       }
    }

    Half diamond string pattern in C: 3

    Enter the string: SIMPLE
    S
    SI
    SIM
    SIMP
    SIMPL
    SIMPLE
    IMPLE
    MPLE
    PLE
    LE
    E

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       char str[20];
       int strLength;
    
       printf("Enter the string: ");
       scanf("%[^\n]", str);
    
      	// count the no. of characters
       for (strLength = 0; str[strLength] != '\0'; strLength++);
    
      	// for first half
       for (int i = 0; i < strLength; i++)
       {
          for (int j = 0; j <= i; j++)
             printf("%c", str[j]);
    
          printf("\n");	// for a new line
       }
    
      	// for second half
       for (int i = 1; i < strLength; i++)
       {
          for (int j = i; j < strLength; j++)
             printf("%c", str[j]);
    
          printf("\n");	// for a new line
       }
    }

    Half diamond string pattern in C: 4

    Enter a string: PROGRAM
    P
    PR
    PRO
    PROG
    PROGR
    PROGRA
    PROGRAM
    PROGRA
    PROGR
    PROG
    PRO
    PR
    P

    Source Code:

    #include <stdio.h>
    #include <stdlib.h>
    
    void main()
    {
       char str[20];
       int len, place;
    
       printf("Enter a string: ");
       scanf("%[^\n]", str);
    
      	// find the length of the string
       for (len = 0; str[len] != '\0'; len++);
       len--;
    
       for (int i = 0; i < (2 *len + 1); i++)
       {
          if (i < len) place = i;
          else place = abs(2 *len - i);
    
          for (int j = 0; j <= place; j++)
             printf("%c", str[j]);
    
          printf("\n");
       }
    }

    Half Pyramid String Pattern in C: 5

    Enter a string: PROGRAM
    P
    PR
    PRO
    PROG
    PROGR
    PROGRA
    PROGRAM

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       char str[20];
    
       printf("Enter a string: ");
       scanf("%[^\n]", str);
    
       for (int i = 0; str[i] != '\0'; i++)
       {
          for (int j = 0; j <= i; j++)
             printf("%c", str[j]);
    
          printf("\n");	// new line
       }
    }

  • Java Program to Find pair of Integers in Array whose sum is given Number

    In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java. Before that, you may go through the following topic in java.


    Algorithm to check the pair of similar numbers present in an array whose sum is a given number

    Step 1: Start
    Step 2: Initiate new Array arr[]
    Step 3: Declare n, value
    Step 4: Take user input for:
    n: number of elements in an array
    arr: elements of an array
    value: for the number to be checked
    Step 5: Loop the entered array:
    for 0 to n-1
    for 0 to n
    if(arr[i] + arr[j] == value)
    print “arr[i] and arr[j]”
    Step 6: Stop


    How to Find all Pairs of Elements in an Array whose sum is equal to a given Number

    import java.util.Scanner;
    
    public class Main
    {
       public static void main(String[] args)
       {
          int[] arr = new int[10];
          int n, value;
          Scanner sc = new Scanner(System.in);
    
          System.out.print("How many elements: ");
          n = sc.nextInt();
    
          System.out.println("Enter the elements: ");
          for (int i = 0; i < n; i++)
             arr[i] = sc.nextInt();
    
           //user input for the value to be checked
          System.out.print("Enter the value to be checked: ");
          value = sc.nextInt();
    
           //Display the sum of pairs
          System.out.println("The pairs are:");
          for (int i = 0; i < (n - 1); i++)
             for (int j = (i + 1); j < n; j++)
                if (arr[i] + arr[j] == value)
                   System.out.println("Arr(" + arr[i] + ", " + arr[j] + ")");
    
       }
    }

    Output:

    How many elements: 5
    Enter the elements:
    1
    2
    5
    3
    4
    Enter the value to be checked: 6
    The pairs are:
    Arr(1, 5)
    Arr(2, 4)


  • Program to Print Diamond Alphabet Patterns in C

    In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a character pattern in C using for loop. So you may go through the following topic in C.

    Pattern 1: Diamond pattern in c using alphabets

    Enter the no. of rows: 8
    A
    ABC
    ABCDE
    ABCDEFG
    ABCDEFGHI
    ABCDEFGHIJK
    ABCDEFGHIJKLM
    ABCDEFGHIJKLMNO
    ABCDEFGHIJKLM
    ABCDEFGHIJK
    ABCDEFGHI
    ABCDEFG
    ABCDE
    ABC
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j, k;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
      	// ASCII value
       int alphabet = 64;
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= rows - i; j++)
             printf(" ");
    
          for (k = 1; k <= i *2 - 1; k++)
             printf("%c", alphabet + k);
    
          printf("\n");
       }
    
       for (i = rows - 1; i > 0; i--)
       {
          for (j = 1; j <= rows - i; j++)
             printf(" ");
    
          for (k = 1; k <= i *2 - 1; k++)
             printf("%c", alphabet + k);
    
          printf("\n");
       }
    }

    Pattern 2: Diamond pattern in c using alphabets

    Enter the no. of rows: 8
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F
    A B C D E F G
    A B C D E F G H
    A B C D E F G
    A B C D E F
    A B C D E
    A B C D
    A B C
    A B
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j, k;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
      	// ASCII value
       int alphabet = 65;
    
       for (i = 0; i <= rows - 1; i++)
       {
          for (j = rows - 1; j >= i; j--)
             printf(" ");
    
          for (k = 0; k <= i; k++)
             printf("%c ", alphabet + k);
    
          printf("\n");;
       }
    
       for (i = 0; i <= rows - 1; i++)
       {
          for (j = -1; j <= i; j++)
             printf(" ");
    
          for (k = 0; k <= rows - i - 2; k++)
             printf("%c ", alphabet + k);
    
          printf("\n");;
       }
    }

    Pattern 3: Diamond pattern in c using alphabets

    Enter the no. of rows: 8
    A
    BAB
    CBABC
    DCBABCD
    EDCBABCDE
    FEDCBABCDEF
    GFEDCBABCDEFG
    HGFEDCBABCDEFGH
    GFEDCBABCDEFG
    FEDCBABCDEF
    EDCBABCDE
    DCBABCD
    CBABC
    BAB
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j, k, l;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       // ASCII value
       int alphabet = 64;
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= rows - i; j++)
             printf(" ");
    
          for (k = i; k >= 1; k--)
             printf("%c", alphabet + k);
    
          for (l = 2; l <= i; l++)
             printf("%c", alphabet + l);
    
          printf("\n");
       }
    
       for (i = rows - 1; i > 0; i--)
       {
          for (j = 1; j <= rows - i; j++)
             printf(" ");
    
          for (k = i; k >= 1; k--)
             printf("%c", alphabet + k);
    
          for (l = 2; l <= i; l++)
             printf("%c", alphabet + l);
    
          printf("\n");
       }
    }

  • Half Diamond Pattern in C using Alphabets

    In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a character pattern in C using for loop. So you may go through the following topic in C.

    Pattern 1: Half Diamond pattern in c using alphabets

    Enter the no. of rows: 5
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D
    A B C
    A B
    A

    Source Code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows - 1; i++)
      {
        for (j = 0; j <= i; j++)
          printf("%c ", (char)(alphabet + j));
    
        printf("\n");
      }
      for (i = rows - 1; i >= 0; i--)
      {
        for (j = 0; j <= i - 1; j++)
          printf("%c ", (char)(alphabet + j));
    
        printf("\n");
      }
    
      getch();
    }

    Pattern 2: Half Diamond pattern in c using alphabets

    Enter the no. of rows: 5
    E
    E D
    E D C
    E D C B
    E D C B A
    E D C B
    E D C
    E D
    E

    Source Code:

    #include <stdio.h>
    #include <math.h>
    
    void main()
    {
       int rows, i, j;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= -rows; i--)
       {
          for (j = rows-1; j >= abs(i); j--)
             printf("%c ", j + 65);
    
          printf("\n");
       }
    }

    Pattern 3: Half Diamond pattern in c using alphabets

    Enter the no. of rows: 5
    E
    E D
    E D C
    E D C B
    E D C B A
    E D C B
    E D C
    E D
    E

    Source Code:

    #include <stdio.h>
    #include <math.h>
    
    void main()
    {
       int rows, i, j;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= -rows; i--)
       {
          for (j = rows-1; j >= abs(i); j--)
             printf("%c ", j + 65);
    
          printf("\n");
       }
    }
  • Half Pyramid of Alphabets in C

    In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in this tutorial, we will create a pyramid character pattern in C using for loop. So you may go through the following topic in C.

    Pattern 1: C program for character/alphabet.

    This program asks for the alphabet till which you want to print.

    Enter the character till which you want to print in uppercase: F
    A
    B B
    C C C
    D D D D
    E E E E E
    F F F F F F

    Source code:

    #include <stdio.h>
    
    int main()
    {
      int i, j;
      char ch, alphabet = 'A';
    
      printf("Enter the character till which you want to print in uppercase: ");
      scanf("%c", &ch);
    
      for (i = 1; i <= (ch - 'A' + 1); ++i)
      {
        for (j = 1; j <= i; ++j)
          printf("%c ", alphabet);
    
        ++alphabet;
        printf("\n");
      }
    
      return 0;
    }

    Pattern 2: C program for character/alphabet.

    This program asks the user for the number of rows that you want.

    Enter the no. of rows: 6
    A
    B B
    C C C
    D D D D
    E E E E E
    F F F F F F

    Source code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
      char ch = 'A';
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      for (i = 0; i <= rows; i++)
      {
        for (j = 0; j <= i; j++)
        {
          printf(" %c", (char)(ch + i));
        }
        printf("\n");
      }
    
      getch();
    }

    Pattern 3: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    A B
    A B C
    A B C D
    A B C D E

    Source code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i < rows; i++)
      {
        for (j = 0; j <= i; j++)
        {
          printf("%c ", (char)(alphabet + j));
        }
        printf("\n");
      }
    
      getch();
    }

    Pattern 4: C program for character/alphabet.

    Enter the no. of rows: 5
    E
    E D
    E D C
    E D C B
    E D C B A

    Source code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = rows - 1; i >= 0; i--)
      {
        for (j = rows - 1; j >= i; j--)
        {
          printf("%c ", (char)(alphabet + j));
        }
        printf("\n");
      }
    
      getch();
    }

    Pattern 5: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    BB
    CCC
    DDDD
    EEEEE
    FFFFFF

    Source code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j, k;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 0; i <= rows; i++)
      {
        for (j = 1; j <= rows - i; j++)
          printf(" ");
    
        for (k = 0; k <= i; k++)
          printf("%c", (char)(i + alphabet));
    
        printf("\n");
      }
    
      getch();
    }

    Pattern 6: C program for character/alphabet.

    Source code:

    #include <stdio.h>
    
    void main()
    {
      int rows, i, j;
    
      printf("Enter the no. of rows: ");
      scanf("%d", &rows);
    
      // ASCII value of alphabet 'A'
      int alphabet = 65;
    
      for (i = 1; i <= rows; i++)
      {
        int count = rows - 1;
        int temp = i;
    
        for (j = 1; j <= i; j++)
        {
          printf("%4c", (char) temp + alphabet - 1);
          temp = temp + count;
          count--;
        }
    
        printf("\n");
      }
    
      getch();
    }

    Pattern 7: C program for character/alphabet.

    Enter the no. of rows: 5
    E
    D D
    C C C
    B B B B
    A A A A A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= i; j++)
          {
             printf("%c ", (char)(rows - i + 1 + 64));
          }
          printf("\n");
       }
    }

    Pattern 8: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    B A
    C B A
    D C B A
    E D C B A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = i; j >= 1; j--)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 9: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    B C
    C D E
    D E F G
    E F G H I

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, k, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          k = i;
          for (j = 1; j <= i; j++, k++)
             printf("%c ", (char)(k + 64));
    
          printf("\n");
       }
    }

    Pattern 10: C program for character/alphabet.

    Enter the no. of rows: 5
    E
    D E
    C D E
    B C D E
    A B C D E

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= 1; i--)
       {
          for (j = i; j <= rows; j++)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 11: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    A B C
    A B C D E
    A B C D E F G
    A B C D E F G H I

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= (i *2 - 1); j++)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 12: C program for character/alphabet.

    Enter the no. of rows: 5
    A
    B C
    D E F
    G H I J
    K L M N O

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, k = 1, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= i; j++, k++)
             printf("%3c", (char)(k + 64));	//3 = TO GIVE FOUR SPACES
    
          printf("\n");
       }
    }

    Pattern 13: C program for character/alphabet.

    Enter the no. of rows: 5
    a
    B c
    D e F
    g H i J
    k L m N o

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, k = 0, l = 1, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= i; j++, k++, l++)
          {
             if (k % 2 == 0)
                printf("%3c", (char)(l + 96));
             else
                printf("%3c", (char)(l + 64));
          }
          printf("\n");
       }
    }

  • Inverted Half Pyramid Pattern of Alphabets in C

    In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in C.

    Pattern 1: C program for character/alphabet.

    Enter the no. of rows: 6
    F F F F F F
    E E E E E
    D D D D
    C C C
    B B
    A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = i; j <= rows; j++)
             printf("%c ", (char)(i + 64));
    
          printf("\n");
       }
    }

    Pattern 2: C program for character/alphabet.

    Enter the no. of rows: 5
    A A A A A
    B B B B
    C C C
    D D
    E

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= 1; i--)
       {
          for (j = 1; j <= i; j++)
             printf("%c ", (char)(i + 64));
    
          printf("\n");
       }
    }

    Pattern 3: C program for character/alphabet.

    Enter the no. of rows: 5
    A B C D E
    A B C D
    A B C
    A B
    A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = 1; j <= rows - i + 1; j++)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 4: C program for character/alphabet.

    Enter the no. of rows: 5
    E D C B A
    D C B A
    C B A
    B A
    A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int i, j, rows;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= 1; i--)
       {
          for (j = i; j >= 1; j--)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 5: C program for character/alphabet.

    Enter the no. of rows: 5
    E F G H I
    D E F G
    C D E
    B C
    A

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int rows, k, i, j;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = rows; i >= 1; i--)
       {
          k = i;
    
          for (j = 1; j <= i; j++, k++)
             printf("%c ", (char)(k + 64));
    
          printf("\n");
       }
    }

    Pattern 6: C program for character/alphabet.

    Enter the no. of rows: 5
    E D C B A
    E D C B
    E D C
    E D
    E

    Source code:

    #include <stdio.h>
    
    void main()
    {
       int rows, i, j;
    
       printf("Enter the no. of rows: ");
       scanf("%d", &rows);
    
       for (i = 1; i <= rows; i++)
       {
          for (j = rows; j >= i; j--)
             printf("%c ", (char)(j + 64));
    
          printf("\n");
       }
    }

    Pattern 7: C program for character/alphabet.

    Enter the no. of rows: 5
    A B C D E
    B C D E
    C D E
    D E
    E

    Source code:

    #include<stdio.h>
    
    void main()
    {
        int rows, i, j;
    
        printf("Enter the no. of rows: ");
        scanf("%d",&rows);
    
        for(i=1; i<=rows; i++)
        {
            for(j=i; j<=rows; j++)
                printf("%c ",(char)(j+64));
            
            printf("\n");
        }
    }