Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, November 19, 2015

C Program to find GCD of two numbers

C Program to find GCD of two numbers

#include<stdio.h>
int main(){
int a,b,i,gcd=1;
printf("Enter any two Number");
scanf("%d%d",&a,&b);
for(i=1;i<=a||i<=b;i++){
if(a%i==0&&b%i==0)
gcd=i;
}
printf("GCD=%d of %d and %d",gcd,a,b);
return 0;
}

C Program to find given numbers are buddies or not

C Program to find given numbers are buddies or not

#include<stdio.h>
int main(){
int a,b,sum1=0,sum2=0;i;
printf("Enter two number");
scanf("%d%d",a,b);
for(i=2;i<=n/2;i++){
if(a%i==0)
sum1+=i;
}
for(i=2;i<=n/2;i++){
if(b%i==0)
sum2+=i;
}
if(sum1==sum2)
printf("Given numbers are buddies");
else
printf("Given numvbers are not buddies");
return 0;
}

Monday, October 12, 2015

C Program to Find Exact Divisor of Given Number


#include<stdio.h>
int main(){int n;
   int i=2;
   scanf("%d",&n);
   while(i<=n/2)
    {
        if(n%i==0)
                  printf("%d,",i);
        i++;
     }
   return 0;
}