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
  6. 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
  7. 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
  8. Question:Write a program to generate the Fibonacci series in c 

    Answer
    #include<stdio.h>
    int main(){
        int k,r;
        long int i=0l,j=1,f;
    
        //Taking maximum numbers form user
        printf("Enter the number range:");
        scanf("%d",&r);
    
        printf("FIBONACCI SERIES: ");
        printf("%ld %ld",i,j); //printing firts two values.
    
        for(k=2;k<r;k++){
             f=i+j;
             i=j;
             j=f;
             printf(" %ld",j);
        }
      
        return 0;
    }
    Sample output: Enter the number range: 15 FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

    1. Report
  9. Question:Fibonacci series using array in c 

    Answer
    #include<stdio.h>
    int main(){
    
        int i,range;
        long int arr[40];
    
        printf("Enter the number range: ");
        scanf("%d",&range);
    
        arr[0]=0;
        arr[1]=1;
    
        for(i=2;i<range;i++){
             arr[i] = arr[i-1] + arr[i-2];
        }
    
        printf("Fibonacci series is: ");
        for(i=0;i<range;i++)
             printf("%ld ",arr[i]);
      
        return 0;
    }
    Sample output: Enter the number range: 20 Fibonacci series is: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

    1. Report
  10. Question:Fibonacci series in c using while loop 

    Answer
    #include<stdio.h>
    int main(){
        int k=2,r;
        long int i=0l,j=1,f;
    
        printf("Enter the number range:");
        scanf("%d",&r);
    
        printf("Fibonacci series is: %ld %ld",i,j);
    
        while(k<r){
             f=i+j;
             i=j;
             j=f;
             printf(" %ld",j);
              k++;
        }
      
        return 0;
    }
    Sample output: Enter the number range: 10 Fibonacci series is: 0 1 1 2 3 5 8 13 21 34

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