WAP to Compute the Sum of two Number by using Function

Engg.... | 05:41 | | Best Blogger Tips
Sum

Statement of C Progream: This Program accepts two Integers and Computes their Sum via addnums() :
There are two methods to write this Program
  1. NON ANSI style
  2. ANSI style
1. NON ANSI style:

#include<stdio.h>
#include<conio.h>
void main()
{
int a , b , result;
clrscr();
printf(" Enter the value of two numbers\n");
scanf("%d%d" , &a , &b);
result = addnums(a , b);
printf(" sum of %d and %d = %d\n" , a , b , result);

}                                                      /* End of main */

/* Function to add two numbers */

int addnums( var1 , var2)
int var1 , var2;
{
int sum;
sum = var1 + var2;
return(sum);
}                                               /* End of Function */

Output:
Enter the value of two numbers
24
68
sum of 24 and 68 = 92


2. ANSI style:

#include<stdio.h>
#include<conio.h>
void main()
{
int a , b , result;
clrscr();
printf(" Enter the value of two numbers\n");
scanf("%d%d" , &a , &b);

result = addnums(a , b);
printf(" sum of %d and %d = %d\n" , a , b , result);

}                                                      /* End of main */

/* Function to add two numbers */

int addnums( int var1 , int var2)
{
int sum;
sum = var1 + var2;
return(sum);

}                                               /* End of Function */

Output:
Enter the value of two numbers
14
18
sum of 14 and 18 = 32

                                                                 That's All
                                                                   
Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

1 comment:

  1. Wow amazing i saw the article with execution models you had posted. It was such informative. Really its a wonderful article. Thank you for sharing and please keep update like this type of article because i want to learn more relevant to this topic.

    Best Linux training in Noida
    Linux Training Institute in Noida
    Shell Scripting Training Institute in Noida

    ReplyDelete