Monday, August 4, 2014

Add between any two numbers using loop

Write a program to add between any two numbers using loop.

SOLUTION:

 /*
 * Add between any two numbers using loop 
 * Written by Shaeed Khan. 
 * Date: 04 Aug 2014
 * Version- 1.0 
 * Language: C
 */

#include < stdio.h >  
#include < stdlib.h > 

void main()
{
 int x;
 int a,b;
 printf("Enter any two numbers :");
 scanf("%d%d",&a,&b);
 x=add(a,b);
 printf("%d ",x);
}

int add(int a,int b)
{
 while(a>0)
 {
  b++;
  a--;
 }
 return b;
} 

No comments:

Post a Comment