1. 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
  2. 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
  3. 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
  4. Question:How to find a b and c in a quadratic equation in the format of ax^2+bx+c: 2x^2+4x+-1. 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
      float a,b,c;
      float d,root1,root2;  
    
      printf("Enter quadratic equation in the format ax^2+bx+c: ");
      scanf("%fx^2%fx%f",&a,&b,&c);
       
      d = b * b - 4 * a * c;
      
      if(d < 0){
        printf("Roots are complex number.\n");
       
        return 0;
      }
     
       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 quadratic equation in the format ax^2+bx+c: 2x^2+4x+-1 Roots of quadratic equation are: 0.000, -2.000






    1. Report
  5. Question:Write a c program to check given string is palindrome number or not 

    Answer
    #include<string.h>
    #include<stdio.h>
    int main(){
      char *str,*rev;
      int i,j;
      printf("\nEnter a string:");
      scanf("%s",str);
      for(i=strlen(str)-1,j=0;i>=0;i--,j++)
          rev[j]=str[i];
          rev[j]='\0';
      if(strcmp(rev,str))
          printf("\nThe string is not a palindrome");
      else
          printf("\nThe string is a palindrome");
      return 0;
    }






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