C Language Basic Program with Solution

    C Language Basic Program with Solution





1) Find Factorial Program


Find Factorical Using  Recursion :

       
#include

#include

int main(){

    int n,answer;

    printf("Enter Number To Find Out Recursion==>");

    scanf("%d",&n);

    answer = findrecursion(n);

    printf("%d",answer);

}

int findrecursion(int val){

    if(val>=1)

    return val*findrecursion(val - 1);

    else

    return 1;

}

       
       




Find Factorical Using  Recursion :


       
#include<stdio.h>

#include<conio.h>

int main()

{

    int n,i;

    int factorial=1;

    printf("Enter Number To Find Out Factorial==>");

    scanf("%d",&n);

    

    for(i=n;i>=1;i--)

    {

        factorial = factorial * i ; 

        

    }

    printf("Factorial ==>%d",factorial);

}

       
       


2) Check Number is Prime Or Not :



#include<stdio.h>

#include<conio.h>

int main()

{

    int no,i;

    int prime=0;

    printf("Please Enter Number To Check Wheather Number is Prime Or Not== >");

    scanf("%d",&no);

    for(i=2;i<=no-1;i++)

    {

        if(no%i==0)

        {

          prime=1;

          }

 }

    if(prime!=1)

    {

        printf("Number is  Prime Number");

    }

    else

    {

        printf("Number is Not Prime Number");

    }

}
       
       


3) Sum Of  Number :


#include<stdio.h>

#include<conio.h>

int main()

{

    int no,m,sum=0;

    printf("Enter Number To Find Their Sum");

    scanf("%d",&no);

  while(no>0)

  {

        m=no%10;

        sum =sum + m;

        no = no/10;

  }

     printf("Sum Of Total Number is ==>%d",sum);

 }

4) Reverse Numbers :


#include<stdio.h>

#include<conio.h>

int main()

{

    int no,m,reverse=0;

    printf("Enter Number==>");

    scanf("%d",&no);

    while(no>0)

    {

        m=no%10;

        reverse = reverse*10 +m;

        no = no/10;

     }

    printf("%d",reverse);

}


5) Palindrome Number :



#include<stdio.h>

#include<conio.h>

int main()

{

    int no , m , reverse = 0 ;

    printf("Enter Number TO Check Number is Palindrome or Not");

    scanf("%d",&no);

    int mainno = no;

    while(no>0)

    {

        m = no % 10;

        reverse = reverse*10 + m ;

        no  = no/10;

        

    }

    // printf("%d",reverse);

    if(reverse == mainno)

    {

        printf("This Number is Palindrome Number");

    }

    else

    {

        printf("This Number is Not Palindrome Number");

    }

}

6) Fibonacci Series:



#include<stdio.h>

#include<conio.h>

int main(){

    int i,n,n1=0,n2=1,n3;

    printf("Enter How Much Fibonacci Number Display==>");

    scanf("%d",&n);

    printf("%d %d ",n1,n2);

    for(i=3;i<=n;i++)

    {

        n3=n1+n2;

        printf("%d ",n3);

        n1 = n2;

        n2 = n3;

     }

}


7) Armstrong Number For Only Three Digit Number :


#include<stdio.h>

#include<conio.h>

int main()

{

    int no, m,number = 0,orgno ;

    printf("Please Enter Number To Check This is Armstrong or Not ==>");

    scanf("%d",&no);

    orgno = no;

    while(no>0)

    {

        m = no % 10;

        number = number + m * m * m ;

        no = no/10;

    }

 if(number == orgno)

    {

        printf("Number is Armstrong Number");

    }

    else

    {

        printf("Number is Not ArmStrong Number");

    }

 }

8) Palindrome Number :


#include<stdio.h>

#include<conio.h>

int main()

{

    int no , m , reverse = 0 ;

    printf("Enter Number TO Check Number is Palindrome or Not");

    scanf("%d",&no);

    int mainno = no;

    while(no>0)

    {

        m = no % 10;

        reverse = reverse*10 + m ;

        no  = no/10;

        

    }

    // printf("%d",reverse);

    if(reverse == mainno)

    {

        printf("This Number is Palindrome Number");

    }

    else

    {

        printf("This Number is Not Palindrome Number");

    }

}


9) Hello World Without Semicolon :

There are Many Tricks To Write Hello World without Semicolon(;) One Of This :

#include<stdio.h>

#include<conio.h>

int main()

{

    if(printf("Hello World")){

        

    }

}


10) Find Number is Odd or Even :



#include<stdio.h>

#include<conio.h>

 int main(void) {

int x;

char ch;

do {

printf ("Enter number To Find Out Odd Or Even:");

scanf ("%d",&x);

if(x%2==0)

{

    printf("number is Even");

}

else if(x%2!=0)

{

printf("Number is Odd");

}

printf ("Do you want to repeat the operation Y/N: ");

scanf (" %c", &ch);

}

while (ch == 'y' || ch == 'Y');

}


11) Decimal  To Binary  :


#include<stdio.h>

#include<conio.h>

int main()

{

    int no,i,a[20];

    printf("Enter Number==>");

    scanf("%d",&no);

    for(i=0;no>0;i++)

    {

        a[i] = no%2 ;

        no = no/2;

    }

    for(i=i-1;i>=0;i--)

    {

        printf("%d",a[i]);

    }

  }


12) Binary To Decimal Conversion  :


#include<stdio.h>

#include<conio.h>

#include<math.h>

int main()

{

    int no,m,count=0,i,decimal=0,orgno;

    printf("Enter Number==>");

    scanf("%d",&no);

    orgno = no ;

    while(no!=0)

    {

        no = no/10;

        count++;

    }

    printf("%d",count);

    for(i=0;i<=count-1;i++)

    {

        m = orgno%10;

        decimal = decimal + m * pow(2, i);

        orgno = orgno/10;

    }

    printf("Decimal Number is ==>%d",decimal);

}

About Author : 

Hello friends, I am Abhi Patel author & founder of Technovichar.com. I am a student of IT engineering. I like to research and write about new things even if it is from any field. You will continue to support us in this way, we will keep on bringing such interesting information for you.



Post a Comment

0 Comments