Showing posts with label Maximum. Show all posts
Showing posts with label Maximum. Show all posts

Write a C program to find maximum or equal between two numbers ?

How to Write a C program to find maximum or equal between two numbers ?


  1. /*Write a C program to find maximum or equal between two numbers */
  2.  
  3.  
  4. #include <stdio.h>
  5.  
  6. int main ()
  7.  
  8. {
  9.     int a,b;
  10.     printf("Find the maximum between two number: ");
  11.     scanf("%d %d", &a, &b);
  12.  
  13.     if ( a > b ){
  14.         printf("Minimum Number: %d\n",a);
  15.     }
  16.  
  17.     if ( b > a ){
  18.         printf("Maximum Number: %d\n",b);
  19.     }
  20.  
  21.     if ( a == b ){
  22.         printf("Number is equal");
  23.     }
  24.  
  25.     return 0;
  26. }

How to Write a C program to find maximum between two numbers ?

Write a C program to find maximum between two numbers.



  1. /*Write a C program to find maximum between two numbers */
  2. #include <stdio.h>
  3. int main ()
  4. {
  5.     int a,b;
  6.     printf("Find the maximum between two number: ");
  7.     scanf("%d %d", &a, &b);
  8.     if ( a < b ){
  9.         printf("Minimum Number:%d\n",a);
  10.     }
  11.     if ( a > b ){
  12.         printf("Maximum Number%d\n",b);
  13.     }
  14.     return 0;
  15. }

Write a C program to find maximum between three numbers ?

Write a C program to find maximum between three numbers.

  1. /*Write a C program to find maximum between three numbers */
  2. #include<stdio.h>
  3. int main ()
  4. {
  5.     int a, b, c, max;
  6.     printf("find maximum between three numbers: ");
  7.     scanf("%d %d %d", &a, &b, &c);
  8.     if( a > b){
  9.         max = a;
  10.     }
  11.     if( b > a){
  12.         max = b;
  13.     }
  14.     if( b > c){
  15.         max = b;
  16.     }
  17.     if( c > a){
  18.         max = c;
  19.     }
  20.    if( a > c ){
  21.        max = a;
  22.    }
  23.    if ( c > b){
  24.     max = c;
  25.    }
  26.    printf("The maximum number is: %d\n", max);
  27.     return 0;
  28. }

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();
    }

C Program To Find Maximum Of Given Numbers

How to write a C Program To Find Maximum Of Given Numbers in C Programming Language ?


Solution For C Program :

/*C Program To Find Maximum Of Given Numbers*/

#include <stdio.h>
void main()
{
void max_three(int,int,int);
int a,b,c;
printf("\nEnter any Three Integers : ");
scanf("%d%d%d", &a, &b, &c);
max_three(a, b, c);
}
void max_three(int x, int y, int z)
{
int d;
if(x > y)
d = x;
else
d = y;
if(d > z)
printf("\nMaximum of Three Numbers : %d", d);
else
printf("\nMaximum of Three Numbers : %d", z);
return;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

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. }