Showing posts with label Minimum. Show all posts
Showing posts with label Minimum. Show all posts

C Program To Find The Maximum And Minimum Value In An Array

How to write a C Program To Find The Maximum And Minimum Value In An Array in C Programming Language ?


Solution For C Program :

/*C Program To Find The Maximum And Minimum Value In An Array*/

#include<stdio.h>
#include<conio.h>
void main()
    {
    int k;
    int a[5],i,j,max=0,min=0;
    printf("Enter how many numbers in array:=");
    scanf("%d",&k);
    printf("enter the numbers:\n");
    for(i=0;i<k;i++)
        {
        scanf("%d",&a[i]);
        }
        max=a[0];
        min=a[0];
        for(i=1;i<k;i++)
            {
            if(a[i]>max)
            {
            max=a[i];
            }
            if(a[i]<min)
            {
            min=a[i];
            }
            }
    printf("Maximum value of array:=%d\n",max);
    printf("Minimum value of array:=%d",min);
    getch();
    }

Max count of chars, Max count of nums and Max count of signs

How to write a C Program to Maximum count of chars, Maximum count of numbers and Maximum count of signs in C Programming Language ?

This C Program to Max count of chars, Max count of nums and Max count of signs.

Solution:


  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4.         int chars=0, nums=0, mchars=0, mnums=0, signs=0, msigns = 0, i;
  5.         char str[500];
  6.         puts("Input string:");
  7.         gets(str);
  8.         for (= 0; str[i]; i++) {
  9.                 if (str[i] >= '0' && str[i] <= '9') {
  10.                         nums++;
  11.                         if (chars > mchars) mchars = chars;
  12.                         if (signs > msigns) msigns = signs;
  13.                         chars = signs = 0;
  14.                 }
  15.                 else {
  16.                         if (nums > mnums) mnums = nums;
  17.                         nums = 0;
  18.                         if ((str[i] >= 'a' && str[i] <= 'z') ||
  19.                                 (str[i] >= 'A' && str[i] <= 'Z')) {
  20.                                 chars++;
  21.                                 if (signs > msigns) msigns = signs;
  22.                                 signs = 0;
  23.                         }
  24.                         else if (str[i] == '*' || str[i] == '+' || str[i] == '-'){
  25.                                 signs++;
  26.                                 if (chars > mchars) mchars = chars;
  27.                                 chars = 0;
  28.                         }
  29.                         else {
  30.                                 if (chars > mchars) mchars = chars;
  31.                                 if (signs > msigns) msigns = signs;
  32.                         }
  33.                 }
  34.         }
  35.         if (nums > mnums) mnums = nums;
  36.         if (chars > mchars) mchars = chars;
  37.         if (signs > msigns) msigns = signs;
  38.         printf("Max count of chars: %d\nMax count of nums: %d\nMax count of signs: %d\n", mchars, mnums, msigns);
  39.         printf("Is chars count bigger than signs count: ");     printf(mchars > msigns ? "true" : "false");
  40.         _getch();
  41. }

C Program to Print Maximum and Minimum Number in Row and Column

How to write a C Program to Print Maximum and Minimum Number in Row and Column in C Programming Language ?

This C Program to Print Maximum and Minimum Number in Row and Column.

Solution:

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int ar[100][100], row, col, i , j, max,min, max2;
  5.     printf("row = ");
  6.     scanf("%d", &row);
  7.     printf("column = ");
  8.     scanf("%d", &col);
  9.     for(= 0 ; i < row ; i++)
  10.     {
  11.         for(= 0 ; j < col ; j++)
  12.         {
  13.             printf("ar[%d][%d] = ", i, j);
  14.             scanf("%d", &ar[i][j]);
  15.         }
  16.     }
  17.     max = ar[0][0];
  18.     min = ar[0][0];
  19.     for(= 0 ; i < row ; i++)
  20.     {
  21.         for(= 0 ; j < col ; j++)
  22.         {
  23.             if(max < ar[i][j])
  24.             {
  25.                 max = ar[i][j];
  26.             }
  27.             if(min > ar[i][j])
  28.             {
  29.                 min = ar[i][j];
  30.             }
  31.         }
  32.     }
  33.     max2 = ar[0][0];
  34.     for(= 0 ; i < row ; i++)
  35.     {
  36.         for(= 0; j < col ; j++)
  37.         {
  38.             if(max2 < ar[i][j])
  39.             {
  40.                 if(ar[i][j] == max)
  41.                 {
  42.                     continue;
  43.                 }
  44.                 max2 = ar[i][j];
  45.             }
  46.         }
  47.     }
  48.     printf("maximum number : %d\nminimum number : %d\nsecond maximum number : %d\n",max, min, max2);
  49.     return 0;
  50. }

C Program to Find max and min in array using pointer concept

How to write a C Program to Find max and min in array using pointer concept in C Programming Language ?


This C Program to Find maximum and minimum in array using pointer concept.

Solution:

  1. /*C Program to find maximum and minimum element in array using pointer */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void max_min(int num[],int length,int *max,int *min);
  6.  
  7. int main()
  8. {
  9.     int len;
  10.     int num[len];
  11.     int i,max,min;
  12.     printf("How many numbers do you wanna input ?");
  13.     scanf("%d",&len);
  14.     printf("Enter %d numbers to find the biggest and small (enter x to terminate)",len);
  15.     for(i=0;i<len-1;i++)
  16.     {
  17.         scanf("%d",&num[i]);
  18.     }
  19.  
  20.     max_min(num,len,&max,&min);
  21.  
  22.     printf("Biggest number :%d",max);
  23.     printf("Smallest number :%d",min);
  24.  
  25.     system("pause");
  26.     return 0;
  27. }
  28.  
  29. void max_min(int num[],int length,int *max,int *min)
  30. {
  31.     int k;
  32.     for(k=0;k<length-1;k++)
  33.     {
  34.         if(num[k]>*max)
  35.             *max=num[k];
  36.             else if(num[k]<*min)
  37.                 *min=num[k];
  38.     }
  39. }

C Program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array

How to write a c program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array in C Programming Language ?


Solution:
/*C Program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array*/
#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10],i,n,max,min;
  clrscr();
  printf("\nEnter the n numbers: ");
  scanf("%d",&n);
  printf("\nEnter  the numbers: ");
  for(i=0;i<n;i++)
{
  scanf("%d",&a[i]);
}
  max=a[0];
  min=a[0];
  for(i=0;i<n;i++)
{
  if(a[i]>max)
{
  max=a[i];
}
  if(a[i]<min)
{
  min=a[i];
}
}
  printf("\nMaximum number is:%d",max);
  printf("\nMinimum number is:%d",min);
  getch();
}

//OUTPUT:
//Enter the n numbers: 4
//Enter the numbers: 1 2 3 4
//Maximum number is:4
//Minimum number is:1