Number conversion (binary,decimal,octal,hexadecimal)
#include<stdio.h>
#include<conio.h>
void main()
{
char base16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
long num;
long cnum[68];
int base,number,i,j;
clrscr();
printf("\nEnter a decimal number to convert : ");
scanf("%ld",&num);
printf("\nEnter base for convert : 2(for binary),8(for octal),16(for hexadecimal) : ");
scanf("%d",&base);
i=0;
while(num!=0)
{
cnum[i]=num%base;
num=num/base;
i++;
}
i=i--;
printf("\nThe number in your base is : ");
for(i=i;i>=0;i--)
{
number=cnum[i];
printf("%c",base16[number]);
}
getch();
}
GCD by recurtion
#include<stdio.h>
#include<conio.h>
int gcd(int m , int n)
{
if(m==0)
return n;
if(n==0)
return m;
return gcd(n, m%n);
}
void main()
{
int m,n;
printf("enter m,n value:");
scanf("%d%d",&m,&n);
printf("the gcd is:%d",gcd(m,n));
getch();
}
Run this and try to understand this
#include<stdio.h>
#include<conio.h>
int nonprime(int p);
void main()
{
long int i,j,n,a[5];
int count=0;
for(i=10000;i<=99999;i++)
{
n=i;j=0;
while(n!=0)
{
a[j]=n%10;
n=n/10;
j++;
}
if((a[4]%2==0) && (a[3]%2!=0) && (nonprime(a[2])) && (a[1]!=a[2]!=a[3]!=a[4]) && (a[0]!=a[2]!=a[3]!=a[4]))
{
count=count+1;
}
else
count=count+0;
}
printf("The number is %d .",count);
}
int nonprime(int p)
{
int j;
for(j=2;j<=p;j++)
{
if(p%j==0)
break;
if(p==j)
return 0;
else
return 1;
}
}
#include<stdio.h>
#include<conio.h>
void main()
{
char base16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
long num;
long cnum[68];
int base,number,i,j;
clrscr();
printf("\nEnter a decimal number to convert : ");
scanf("%ld",&num);
printf("\nEnter base for convert : 2(for binary),8(for octal),16(for hexadecimal) : ");
scanf("%d",&base);
i=0;
while(num!=0)
{
cnum[i]=num%base;
num=num/base;
i++;
}
i=i--;
printf("\nThe number in your base is : ");
for(i=i;i>=0;i--)
{
number=cnum[i];
printf("%c",base16[number]);
}
getch();
}
GCD by recurtion
#include<stdio.h>
#include<conio.h>
int gcd(int m , int n)
{
if(m==0)
return n;
if(n==0)
return m;
return gcd(n, m%n);
}
void main()
{
int m,n;
printf("enter m,n value:");
scanf("%d%d",&m,&n);
printf("the gcd is:%d",gcd(m,n));
getch();
}
#include<stdio.h>
#include<conio.h>
int nonprime(int p);
void main()
{
long int i,j,n,a[5];
int count=0;
for(i=10000;i<=99999;i++)
{
n=i;j=0;
while(n!=0)
{
a[j]=n%10;
n=n/10;
j++;
}
if((a[4]%2==0) && (a[3]%2!=0) && (nonprime(a[2])) && (a[1]!=a[2]!=a[3]!=a[4]) && (a[0]!=a[2]!=a[3]!=a[4]))
{
count=count+1;
}
else
count=count+0;
}
printf("The number is %d .",count);
}
int nonprime(int p)
{
int j;
for(j=2;j<=p;j++)
{
if(p%j==0)
break;
if(p==j)
return 0;
else
return 1;
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন