Skip to main content

Count Elements

// Counting Elements

#include<stdio.h>
#define SIZE 10

void count();
int main()
{
    int a[SIZE] = {'\0'};
    int i,n;

    printf("Enter the Number of Elements [Max = %d] : ",SIZE);
    scanf("%d",&n);

    if(n>SIZE)
    {
        printf("INVALID INPUT !! ");
    }
    else
    {
        for(i=0; i<n; i++)
        {
            printf("Enter the Elements a[%d] : ",i);
            scanf("%d",&a[i]);
        }
        count(a);
    }
    return 0;
}

void count(int a[])
{
    int i;
    for(i=0;a[i];i++);
    printf("\nTotal Number of Elements Are : %d",i);
}


Comments

Popular posts from this blog

Search an Element

// Searching an Element #include<stdio.h> #define SIZE 10 void search(int a[],int no) {    int i, flag = 0;    for(i=0;i<=a[i];i++)    {        if(no == a[i])        {            printf("%d Found at Position %d And Index No is %d",no,i+1,i);            flag=1;        }    }    if(!flag)    {        printf("%d not Found!!",no);    } } int main() {    int i,no,elements;    int a[SIZE];    printf("Enter a Number of Elements : ");    scanf("%d",&elements);    for(i=0;i<elements;...

Lower Triangular Matrix

// Lower Triangular Matrix #include<stdio.h> int main() {     int i,j,k,m,s=1,rc;     printf("Enter the No of Raws and Columns : ");     scanf("%d",&rc);       for(i=1;i<rc;i++)     {         for(m=0;m<i;m++) // for loop which prints numbers.         {             printf("%3d",s);             s++;         }         for(j=rc;j>i;j--) // for loop which prints 0.         {             printf("  0");         }         printf("\n");     }     return 0; }