Q:

C Program to Find the Sum of Three Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program to Find the Sum of Three Numbers (Simple Way)
  • C Program to Find the Sum of Three Numbers using Function
  • C Program to Find the Sum of Three Numbers using Array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

 Program to Find the Sum of Three Numbers (Simple Way)

Algorithm

  • Program Start
  • Declaring Variables
  • Input Three Numbers from User
  • Calculating Sum of Three Numbers (sum = x + y + z)
  • Displaying the Sum of Three Numbers
  • Program End

Program

//C Program to Find the Sum of Three Numbers (Simple Way)

#include<stdio.h>
int main()
{
  //Declaring Four Variables
  
    int x, y, z, sum;           

   printf("Enter Three Numbers : \n");    
   scanf("%d %d %d",&x, &y, &z);     //Input Numbers

  //Calculating Sum of three numbers

   sum = x + y +z;
   printf("Sum of Three Numebers is : %d", sum);    

   return 0;
}

Output

Enter Three Numbers :
10
20
38

Sum of Three Numebers is : 68

C Program to Find the Sum of Three Numbers Using Function

Algorithm

  • Program Start
  • Declaring variables
  • Input three Number
  • Calling Function to calculate Sum of three Numbers
  • Print the Sum of three Numbers
  • Program End

Program

//C Program to Find the Sum of Three Numbers Using Function

#include<stdio.h>
int sum(int, int, int);
int main()
{
 //Declaring Variables
   int x, y, z, s;

  //Input Numbers From User
   printf("Enter Three Numbers : \n");
   scanf("%d %d %d",&x, &y, &z);

 //Calling Function to find the Sum of three numbers
   s = sum(x,y,z);
   printf("Sum of Three Numbers is : %d \n", s);


   return 0;
}
int sum(int a, int b, int c)
{
    return (a+b+c);
}

Output

Enter Three Numbers :
12
18
10
Sum of Three Numbers is : 40

C Program to Find the Sum of Three Numbers Using Array

Algorithm

  • Program Start
  • Declaring variables
  • Input Numbers From the User
  • Calculating Sum
  • Display the Sum of three Numbers
  • Program End

Program

//C Program to Find the Sum of Three Numbers Using Array

#include<stdio.h>
int main()
{ 
  //Declaring  Variables

   int i, sum = 0, a[3]; 
   
   printf("Enter Three Numbers : \n");
   for(i=0; i<3; i++)
   {
    scanf("%d",&a[i]);  //Input Numbers
   }

//Calculating Sum
   for(i=0; i<3;i++)
   {
    sum = sum + a[i];
   }
   printf("Sum of Three Numebers is : %d", sum);
  
 return 0;
}

Output

Enter Three Numbers :
10
29
11
Sum of Three Numbers is : 50

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to Find the Sum of first n even Numbers... >>
<< C Program to Find the Sum of n odd Numbers...