954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Smallest, Largest & Sum of 5 numbers

0
By clarence_cool03 on May 15th, 2009 10:01 am

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

#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

saranyaachanti
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

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.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
#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);
}
arindam31
Light Poster
48 posts since Mar 2011
Reputation Points: 2
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You