Statement of C Progream: This Program accepts two Integers and Computes their Sum via addnums() :
There are two methods to write this Program
- NON ANSI style
- 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);
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
0 comments:
Post a Comment