1. Question:C program to find whether a number is palindrome or not 

    Answer
    #include<stdio.h>
    int main(){
        int num,r,sum=0,temp;
    
        printf("Enter a number: ");
        scanf("%d",&num);
    
        temp=num;
        while(num){
             r=num%10;
             num=num/10;
             sum=sum*10+r;
        }
        if(temp==sum)
             printf("%d is a palindrome",temp);
        else
             printf("%d is not a palindrome",temp);
    
        return 0;
    }
    Sample output: Enter a number: 131 131 is a palindrome






    1. Report
  2. Question:Write a c program for palindrome within a range. 

    Answer
    #include<stdio.h>
    int main(){
        int num,r,sum,temp;
        int min,max;
    
        printf("Enter the minimum range: ");
        scanf("%d",&min);
    
        printf("Enter the maximum range: ");
        scanf("%d",&max);
    
        printf("Palindrome numbers in given range are: ");
        for(num=min;num<=max;num++){
             temp=num;
             sum=0;
    
             while(temp){
                 r=temp%10;
                 temp=temp/10;
                 sum=sum*10+r;
             }
             if(num==sum)
                 printf("%d ",num);
        }
        return 0;
    }
    Sample output: Enter the minimum range: 1 Enter the maximum range: 50 Palindrome numbers in given range are: 1 2 3 4 5 6 7 8 9 11 22 33 44






    1. Report
  3. Question:How to check if a number is a palindrome using for loop? 

    Answer
    #include<stdio.h>
    int main(){
        int num,r,sum=0,temp;
    
        printf("Enter a number: ");
        scanf("%d",&num);
    
        for(temp=num;num!=0;num=num/10){
             r=num%10;
             sum=sum*10+r;
        }
        if(temp==sum)
             printf("%d is a palindrome",temp);
        else
             printf("%d is not a palindrome",temp);
    
        return 0;
    }
    Sample output: Enter a number: 1221 1221 is a palindrome






    1. Report
  4. Question:C program to check if a number is palindrome using recursion 

    Answer
    #include<stdio.h>
    
    int checkPalindrome(int);
    int main(){
        int num,sum;
    
        printf("Enter a number: ");
        scanf("%d",&num);
    
        sum = checkPalindrome(num);
    
        if(num==sum)
             printf("%d is a palindrome",num);
        else
        printf("%d is not a palindrome",num);
    
        return 0;
    }
    
    int checkPalindrome(int num){
    
        static int sum=0,r;
    
        if(num!=0){
             r=num%10;
             sum=sum*10+r;
             checkPalindrome(num/10);
        }
    
        return sum;
    }
    Sample output: Enter a number: 25 25 is not a palindrome






    1. Report
  5. Question:C program to calculate roots of a quadratic equation 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
      float a,b,c;
      float d,root1,root2;  
    
     
      printf("Enter a, b and c of quadratic equation: ");
      scanf("%f%f%f",&a,&b,&c);
       
      d = b * b - 4 * a * c;
      
      if(d < 0){
        printf("Roots are complex number.\n");
    
        printf("Roots of quadratic equation are: ");
        printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a));
        printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a));
      
        return 0; 
      }
      else if(d==0){
       printf("Both roots are equal.\n");
    
       root1 = -b /(2* a);
       printf("Root of quadratic equation is: %.3f ",root1);
    
       return 0;
      }
      else{
       printf("Roots are real numbers.\n");
      
       root1 = ( -b + sqrt(d)) / (2* a);
       root2 = ( -b - sqrt(d)) / (2* a);
       printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
      }
    
      return 0;
    }
    Sample output: Enter a, b and c of quadratic equation: 2 4 1 Roots are real numbers. Roots of quadratic equation are: -0.293, -1.707






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd