37. Decimal to Binary :—
#include<stdio.h>
int main()
{
int i,sum,n,r;
printf("enter a value of n ");
scanf("%d",&n);
i=1;
sum=0;
while(n>0)
{
r=n%2;
sum=sum+i*r;
n=n/2;
i=i*10;
}
printf("%d",sum);
return 0;
}
37. Decimal to Binary :—
#include<stdio.h>
int main()
{
int i,sum,n,r;
printf("enter a value of n ");
scanf("%d",&n);
i=1;
sum=0;
while(n>0)
{
r=n%2;
sum=sum+i*r;
n=n/2;
i=i*10;
}
printf("%d",sum);
return 0;
}
36. Sum of all odd position and even position digits :—
#include<stdio.h>
int main()
{
int i,sumo,sume,n,r;
i=0,sumo=0,sume=0;
printf("enter a value of n ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
if(i%2==0)
{
sume=sume+r;
printf("sum of even positions=%d\n",sume);
}
else
{
sumo=sumo+r;
printf("sum of odd positions=%d\n",sumo);
}
n=n/10;
i++;
}
return 0;
}
35. Sum of all odd digits :—
#include<stdio.h>
int main()
{
int sum,n,r;
sum=0;
printf("enter a value of n ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
if(r%2!=0)
{
sum=sum+r;
}
n=n/10;
}
printf("%d",sum);
return 0;
}
34. Count total numbers of 0 in a number :—
#include<stdio.h>
int main()
{
int count,n,r;
count=0;
printf("enter a value of n ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
if(r==0)
{
count++;
}
n=n/10;
}
printf("%d",count);
return 0;
}
33. Perfect number checking :—
#include<stdio.h>
int main()
{
int i,n,r,sum;
printf("enter a value of n ");
scanf("%d",&n);
sum=0;
for(i=1;i<n;i++)
{
r=n%i;
if(r==0)
{
sum=sum+i;
}
}
if(sum==n)
{
printf("It is a perfect number");
}
else
{
printf("It is not a perfect number");
}
return 0;
}
32.Sum of all factors :—
#include<stdio.h>
int main()
{
int i,n,r,sum;
printf("enter a value of n ");
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
sum=sum+i;
}
}
printf("%d",sum);
return 0;
}
31.Prime number checking :—
#include<stdio.h>
int main()
{
int i,n,r,count;
printf("enter a value of n ");
scanf("%d",&n);
count=0;
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
count++;
}
}
if(count==2)
{
printf("It is a prime number");
}
else
{
printf("It is not a prime number");
}
return 0;
}
30.Count total number of factors :—
#include<stdio.h>
int main()
{
int i,n,r,count;
printf("enter a value of n ");
scanf("%d",&n);
count=0;
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
count++;
}
}
printf("%d",count);
return 0;
}
29. Print all factors of a number :—
#include<stdio.h>
int main()
{
int i,n,r;
printf("enter a value of n ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
r=n%i;
if(r==0)
{
printf("%d",i);
}
}
return 0;
}
28. Armstrong number checking :—
#include<stdio.h>
int main()
{
int i,n,m,k,r,sum;
printf("enter value of n ");
scanf("%d",&n);
m=n;
k=0;
while(n>0)
{
n=n/10;
k++;
}
n=m;
sum=0;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+pow(r,k);
}
if(sum==m)
{
printf("It is an Armstrong number");
}
else
{
printf("It is not an Armstrong number");
}
return 0;
}