Skip to main content

Featured

C Program to Check Prime Number Using Efficient Logic

  Introduction A prime number is a number that has exactly two distinct positive divisors: 1 and itself. In this program, we check whether a given number is prime or not using a simple and efficient logic. This type of program is commonly used in mathematics, competitive programming, and basic algorithm learning for beginners in C programming. Problem Statement The task is to write a C program that determines whether a given integer is a prime number or not. The program takes a single integer input from the user and analyzes its divisibility. If the number has no divisors other than 1 and itself, it should be identified as a prime number; otherwise, it is not prime. This problem is important in number theory and has practical relevance in areas such as cryptography, data validation, and algorithm design.  Algorithm / Logic Explanation To check whether a number is prime, we need to verify that it is not divisible by any number other than 1 and itself. The algorithm follows a si...

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

๐ŸŒ™