Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C Program to Reverse an Array

 

πŸ” C Program to Reverse an Array

#include<stdio.h>
int main()
{
    int num, a[100];
    printf("Enter size of the array:\n");
    scanf("%d", &num);
    if(num <= 0)
    {
        printf("!invalid Array Size:\n");
        return 1;
    }
    printf("Enter %d elements:\n", num);
    for(int i = 0; i < num; i++)
    {
        scanf("%d", &a[i]);
    }
    printf("\nBefore reverse:\n");
    for(int i = 0; i < num; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\nAfter reverse:\n");
    for(int i = num - 1; i >= 0; i--)
    {
        printf("%d ", a[i]);
    }
}
  

πŸ“ Explanation:

This program takes an array of integers from the user, displays the original array, and then prints the elements in reverse order. It uses a loop to first store the input values, and then another loop from the end of the array to the beginning for reverse display.

πŸ’‘ Sample Output:

Enter size of the array:
5
Enter 5 elements:
10 20 30 40 50

Before reverse:
10 20 30 40 50
After reverse:
50 40 30 20 10
  

πŸ” Keywords:

Reverse array in C, C program for reverse, loop reverse logic, array operations in C, beginner array program

Comments

Popular Posts

πŸŒ™