C Programming Codes Or Programs Part 06 | Programs Of C Programming

Hello guys, welcome back to my blog. In this article, I will share C program codes. The codes which I am sharing have no errors. If you want an article on some other topics then comment us below in the comment section. You can also catch me @ Instagram – Chetan Shidling.

C Programming Codes Or Programs | Programs Of C Programming

C Programming Codes

22. Write a C program to convert binary value to decimal value.

#include<stdio.h>
int bintodec(int n1);
int main()
{
int n1,res;
printf(“enter the binary number(1s and 0s)n”);
scanf(“%d”,&n1);
res=bintodec(n1);
printf(“Coverted Equivalent decimal = %dn”,res);
return 0;
}
//Chetan Shidling
int bintodec(int n1)
{
int dec=0,base=1,rem;
while(n1>0)
{
rem=n1%10;
dec=dec+(rem*base);
n1=n1/10;
base=base*2;
}
return dec;
}
Output:

enter the binary number(1s and 0s)
0110
Converted Equivalent decimal = 6
23. Write a C program to convert decimal value to binary value.

#include<stdio.h>
int dectobin(int dec);
int main()
{
int dec,res;
printf(“enter the decimal numbern”);
scanf(“%d”,&dec);
res=dectobin(dec);
printf(“Coverted Equivalent binary = %dn”,res);
return 0;
}
//CS Electrical & Electronics
int dectobin(int dec)
{
if(dec==0)
return 0;
else
{
return((dec%2)+(10*dectobin(dec/2)));
}
}
Output:
enter the decimal number
8
Coverted Equivalent binary = 1000

 

24. Write a C program for palindrome.

#include<stdio.h>
int pal(int num1);
int main()
{
int num1,rev,temp;
printf(“enter the numbern”);
scanf(“%d”,&num1);
temp=num1;
rev=pal(num1);
if(rev==temp)
printf(“the entered no. is palindromen”);
else
{
printf(“the entered no. is not a palindromen”);
}
return 0;
}
//CS Electrical & Electronics
int pal(int num1)
{
int rem,rev=0,num;
do
{
rem=num1%10;
rev=(rev*10)+rem;
num1=num1/10;
}
while(num1!=0);
{
return rev;
}
}
 
Output:
enter the number
121
the entered no. is palindrome
enter the number
425
the entered no. is not a palindrome

 

25. Write a C program to find the second largest number among the three numbers.

#include<stdio.h>          
int lar(int n1,int n2,int n3);
int main()
{
int a,b,c;
printf(“Enter 3 no’s to find 2nd largest amongn”);
scanf(“%d%d%d”,&a,&b,&c);
lar(a,b,c);
return 0;
}
int lar(int n1,int n2,int n3)
{
if(n1>n2)
{
     if(n1>n3)
                {
     printf(“%d is the second largest among threen”,n3);
     }
     else
     {
     printf(“%d is the second largest among threen”,n1);
      }
}
else if (n2>n3)
{
       if(n2>n1)
       {
       printf(“%d is the second largest among threen”,n1);
        }
        else
        {
        printf(“%d is the second largest among threen”,n2);
        }
}
else if (n3>n1)
{
        if(n3>n2)
        {
        printf(“%d is the second largest among threen”,n2);
         }
         else
         {
         printf(“%d is the second largest among threen”,n3);
         }
}
return 0;
}
Output:
Enter 3 no’s to find 2nd largest among
89
105
74
89 is the second largest among three

26. Write a C program to find the second smallest number among the three numbers.

#include<stdio.h>          
int lar(int n1,int n2,int n3);
int main()
{
int a,b,c;
printf(“Enter 3 no’s to find 2nd smallest amongn”);
scanf(“%d%d%d”,&a,&b,&c);
lar(a,b,c);
return 0;
}
int lar(int n1,int n2,int n3)
{
if(n1>n2)
{
     if(n1<n3)
     {
     printf(“%d is the second smallest among threen”,n1);
     }
     else
    {
     printf(“%d is the second smallest among threen”,n3);
     }
}
else if (n2>n3)
{
     if(n2<n1)
     {
     printf(“%d is the second smallest among threen”,n2);
     }
     else
     {
     printf(“%d is the second smallest among threen”,n1);
     }
}
else if (n3>n1)
{
     if(n3<n2)
     {
     printf(“%d is the second smallest among threen”,n3);
     }
     else
     {
     printf(“%d is the second smallest among threen”,n2);
     }
}
return 0;
}
Output:
Enter 3 no’s to find 2nd smallest among
30
10
20
20 is the second smallest among three
 
I hope this article many help you all a lot. If you want some other code then comments us below in the comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *