Sunday, 20 October 2013

Basic Question -4 (find divisor)

     Write a Program to take integer as input & find out all its divisor & sum of  Divisor .

Algorithm :

Simply make a for loop & check for each no . Is it divider of given no or not . IF it is divider of given no add to sum.

C PRogram :


 #include<stdio.h>  
 int div_sum(int b) //funtion def  
 {  
  int i=1,sum=0;  
  printf("divisor are : ");  
  for(i=1;i<b;++i)  
   {  
    if(b%i==0)  
    {   
       printf(" %d ",i);  
    sum=sum+i; // save   
  }  }  
   return(sum);  
 }  
 int main()  
  {  
       int a,m;  
       printf(" inter an Integer no. : ");  
       scanf("%d",&a);  
       m=div_sum(a);  
    printf("sum is = %d",m);  
 }   

OUTPUT :
find divisor of given no in c

1 comment:

  1. Hi, I wish for to subscribe for this blog to get hottest updates, so where can i do
    iit please assist.

    Feel free to surf to mmy web site; Xbox-Live-Code-Generator

    ReplyDelete

THANKS FOR UR GREAT COMMENT

Blogger Widgets