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 find the largest element in an array using simple iteration

Find Largest Element in Array - C Program

πŸ” Find Largest Element in an Array (C Program)

#include<stdio.h>
int main( )
{
    int num,a[100];
    printf("Enter the size of the array:\n");
    scanf("%d",&num);
    if(num<=0)
    {
        printf("Invalid array size");
        return 1;
    }
    printf("Enter %d elements into the array:\n", num);
    for(int i=0;i<num;i++)
    {
        scanf("%d",&a[i]);
    }
    int max=a[0];
    for(int i=0;i<num;i++)
    {
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    printf("The largest element in array is %d\n",max);
}
  

πŸ“˜ Explanation:

πŸ”Ή The program first reads the size and elements of the array.
πŸ”Ή It initializes `max` with the first element.
πŸ”Ή Then it iterates through all elements and updates `max` whenever a larger value is found.
πŸ”Ή Finally, it prints the largest element.

πŸ§ͺ Sample Output:

Enter the size of the array:
5
Enter 5 elements into the array:
10 45 23 89 34
The largest element in array is 89
    

🏷️ Keywords:

C program largest element, find max in array, array maximum value, beginner array program, C logic for max element

Comments

Popular Posts

πŸŒ™