Showing posts with label programs of function. Show all posts
Showing posts with label programs of function. Show all posts

write a program which takes a number and return the sum of its digits using function

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
int hcf(int,int);
void main()
{ clrscr();
  int a,b;
  cout<<"enter the numbers:";
  cin>>a>>b;
  cout<<"HCF of two number is:"<<hcf(a,b);
  getch();
}
 int hcf(int x,int y)
 {
  if(x>y)
  { for(int i=y;i>0;i--)
    { if(x%i==0&&y%i==0)
       return i;
    }
  }
  else
   for(int i=x;i>0;i--)
    { if(x%i==0&&y%i==0)
      return i;
    }
}

find hcf using function

#include<iostream.h>
#include<conio.h>
int hcf(int,int);
void main()
{ clrscr();
  int a,b;
  cout<<"enter the numbers:";
  cin>>a>>b;
  cout<<"HCF of two number is:"<<hcf(a,b);
  getch();
}
 int hcf(int x,int y)
 {
  if(x>y)
  { for(int i=y;i>0;i--)
    { if(x%i==0&&y%i==0)
       return i;
    }
  }
  else
   for(int i=x;i>0;i--)
    { if(x%i==0&&y%i==0)
      return i;
    }
}

basic of function

#include<stdio.h>
#include<conio.h>
void mon();
void sat();
void main()
{
 clrscr();
 sat();
 sat();
 sat();
 mon();
 getch();
 }
 void mon()
 {
  sat();
  }
 void sat()
 {
  static int i;
  printf("\n%d",i);
  i++;
  }