C Program to Classify Students by Gender Using Array

 #include<stdio.h>


int main()

{

    int i, mcount=0, fcount=0, tcount=0;

    char a[75];


    printf("Enter the gender of 6 students (m/f/t): ");


    for(i=0;i<6;i++)

    {

        scanf(" %c",&a[i]);   // space before %c avoids input issue

    }


    for(i=0;i<6;i++)

    {

        if(a[i]=='m')

            mcount++;

        else if(a[i]=='f')

            fcount++;

        else

            tcount++;

    }


    printf("\nMale count = %d",mcount);

    printf("\nFemale count = %d",fcount);

    printf("\nTrans count = %d",tcount);

}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices