Sunday 6 March 2022

C Program To Find max and min term in the given number sequence

 Min term & Max term

Code :

#include<stdio.h>

int main()
{
    int seq, max=0, min=1;
   
    printf("====================================\n");
    printf("\t   Min and Max term\n");
    printf("====================================\n");
   
    printf("Enter sequence of numbers, \n(Terminated by -1) : ");
    scanf("%d", &seq);
    if(seq == -1)
    {
        printf("\n-----------------------------------\n");
        printf("You didn't have entered any sequence !!\n");
        printf("-----------------------------------\n");

        return 0;
    }
    while(seq != -1)
    {
        scanf("%d", &seq);
        if(seq == -1)
        {
           break;
        }
        if(max < seq)
        {
            max = seq;
        }
        if(min > seq)
        {
           min = seq;
        }
    }
    printf("\n-----------------------------------\n");
    printf("  Minimum term in sequence = %d\n", min);
    printf("  Maximum term in sequence = %d\n", max);
    printf("-----------------------------------\n");
    return 0;
}


Come again Learn again !

« iCodeBuzz »


No comments:

Post a Comment