C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
Decimal to binary conversion in c using recursion
Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples
Subscribe to:
Post Comments (Atom)
14 comments:
Thanks,
this program help me alot.
would you please tell me best book to learn C.
'the complete reference'-by Herbert Schildt.
'let us c'-by yashwant kanetkar.
'programming in ANSI C'-by E Balaguruswamy.
njdskl
What does “static” mean in a C program?
how can you convert decimal array into binary?
static means once we gave static variabe a value...then in the whole execution..the value is hold by the variable even if the it not in the scope
#include
int findgcd(int,int);
int main()
{
int i;
int j=0;
int a[10];
printf("enter a number:");
scanf("%d",&i);
while(i)
{
int n=i%2;
a[j]=n;
j++;
i=i/2;
}
j--;
while(j>=0)
{
printf("%d",a[j]);
j--;
}
Won't work for numbers greater that 1023
you could use following code
#include
void to_binary(int n)
{
int remainder;
if(n != 0)
{
remainder = n % 2;
to_binary(n/2);
printf("%d", remainder);
}
}
int main()
{
int n;
scanf("%d", &n);
to_binary(n);
return 0;
}
Programming in C - Kernigan & Ritchie
binaryNo is not initialized to anything. should not it return a garbage value?
i have a very simple and shortest code to find binary of any number
/*********************************************************************************/
/********** binary conversion through recursion *******************************/
/*********************************************************************************/
// by Ammar yasir
// Elect.Engineering student
// NAmal College Mianwali
// may 11, 2014
#include
int binary(int num)
{
int z;
if(num==1)
{
printf("%d",num);
return 1;
}
z=num%2;
num=num>>1;
printf(" %d ",z,binary(num));
}
int main()
{
int num;
printf("enter a number ");
scanf("%d",&num);
binary(num);
return 0;
}
are you kidding me?
int convert(int num,int factor,int src,int dst){
return (!num)?0:(factor*(num%dst)+convert(num/dst,factor*src,src,dst));
}
This is one of the simplest one :
/*Program to print binary equivalent of any number*/
#include
int binary(int);
void main()
{
int num;
printf("Enter any number :\n");
scanf("%d", &num);
printf("Binary equivalent of %d is : ", num);
binary(num);
printf("\n");
}
int binary(int n)
{
if(n==0)
{
printf("0");
return 0;
}
else
{
binary(n/2);
printf("%d",n%2);
}
}
int binary(int dec){
int rem=dec%2;
if(dec==1 || dec==0)
return dec;
else return rem + (binary(dec/2)*10);
}
Post a Comment