Smallest, Largest & Sum of 5 numbers UserPageVisits:1921 active 80 80 DaniWeb 561 60 2011-07-19T14:12:12+00:00 https://www.daniweb.com/programming/software-development/code/217364/smallest-largest-sum-of-5-numbers

Smallest, Largest & Sum of 5 numbers

clarence_cool03

{-='Smallest, Largest & Sum of 5 numbers using Dev-C LaNGuaGe'=-}

1,921 Views
About the Author
code snippet
#include <stdio.h>

int main(void)  
{
//  Local Declarations
    int num1, num2, num3, num4, num5;
    int choice;
    int smallest, largest;
    int sum;
    int average;

//  Statements
    printf("Please enter 5 numbers: ");
    scanf("%d %d %d %d %d", &num1, &num2, &num3, &num4, &num5);
    
    printf("======MAIN MENU====== \n");
    printf("[1] Add \n");
    printf("[2] Find the Average\n");
    printf("[3] Find the smallest \n");
    printf("[4] Find the largest \n");
    printf("Enter your choice...");
    scanf("%d", &choice);
    
    switch(choice) 
       {
          case 1 : sum = num1 + num2 + num3 + num4 + num5;
                   printf("The sum of the numbers are: %d\n", sum);
                   break;
          case 2 : average = (num1 + num2 + num3 + num4 + num5) / 5;
                   printf("The average of the numbers are: %d\n", average);
                   break;
          case 3 : // Finding the smallest
                   smallest = num1;
                   if (num2 < num1)
                       smallest = num2;
                   if (num3 < num2)
                       smallest = num3;
                   if (num4 < num3)
                       smallest = num4;
                   if (num5 < num4)
                       smallest = num5;
                                  
                   else if (num5 < num1)
                       smallest = num5;
                       printf("The smallest number is: %d\n", smallest);
                   break;
          case 4 : // Finding the largest
                   largest = num1;
                   if (num2 > num1)
                       largest = num2;
                   if (num3 > num2)
                       largest = num3;
                  if (num4 > num3)
                       largest = num4;
                   if (num5 > num4)
                       largest = num5;
                                  
                   else if (num5 > num1)
                      largest = num5;
                   printf("The largest number is: %d\n", largest);
                   break;
          default : printf("Invalid choice!\n");           
       }// end of switch
    
    system("pause");
    return 0;
}// main

excellent ,super i really liked it

WaltP 2,905

You would. It's lame, rigid, and two years old. There are much better ways, and many have been posted in the past two years.

mattdeximo commented: you are a big help in my activity thankyou +0
#include<stdio.h>
void main()
{
  int arr[]={102,201,30,41,5,6,17,8,9,10};
  int sml,lar,sum;
  int i;
  sum=0;
  for(i=0;i<10;i++)
    sum=sum+arr[i];
  printf("The sum is %d\n",sum);
  lar=arr[0];
  sml=arr[0];
  for(i=1;i<10;i++)
    {
    if (lar<arr[i])
       lar = arr[i];
    }
   printf("The largest number is %d\n",lar);
    for(i=1;i<10;i++)
    {
    if (sml>arr[i])
       sml = arr[i];
    }
   printf("The smallest number is %d\n",sml);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.