1. Question:Find power of a number using recursion using c program 

    Answer
    #include<stdio.h>
    int main(){
      int pow,num;
      long int res;
      long int power(int,int);
      printf("\nEnter a number: ");
      scanf("%d",&num);
      printf("\nEnter power: ");
      scanf("%d",&pow);
      res=power(num,pow);
      printf("\n%d to the power %d is: %ld",num,pow,res);
      return 0;
    }
      int i=1;
      long int sum=1;
      long int power(int num,int pow){
          if(i<=pow){
               sum=sum*num;
              power(num,pow-1);
          }
          else
          return sum;
      }

    1. Report
  2. Question:How to find size of integer data type without using sizeof operator in c programming language 

    Answer
    #include<stdio.h>
    int main(){
      int *ptr = 0;
      ptr++;
      printf("Size of int data type:  %d",ptr);
      return 0;
    }

    1. Report
  3. Question:How to find size of double data type without using sizeof operator in c programming language 

    Answer
    #include<stdio.h>
    int main(){
      double *ptr = 0;
      ptr++;
      printf("Size of double data type:  %d",ptr);
      return 0;
    }

    1. Report
  4. Question:How to find size of structure data type without using sizeof operator in c programming language 

    Answer
    #include<stdio.h>
    struct student{
        int roll;
        char name[100];
        float marks;
    };
    
    int main(){
      struct student *ptr = 0;
      ptr++;
      printf("Size of the structure student:  %d",ptr);
      return 0;
    }

    1. Report
  5. Question:How to find size of union data type without using sizeof operator in c programming language 

    Answer
    #include<stdio.h>
    union student{
        int roll;
        char name[100];
        float marks;
    };
    
    int main(){
      union student *ptr = 0;
      ptr++;
      printf("Size of the union student:  %d",ptr);
      return 0;
    }

    1. Report
  6. Question:Write a simple code for linear search in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
        int a[10],i,n,m,c=0;
    
        printf("Enter the size of an array: ");
        scanf("%d",&n);
    
        printf("Enter the elements of the array: ");
        for(i=0;i<=n-1;i++){
             scanf("%d",&a[i]);
        }
    
        printf("Enter the number to be search: ");
        scanf("%d",&m);
        for(i=0;i<=n-1;i++){
             if(a[i]==m){
                 c=1;
                 break;
             }
        }
        if(c==0)
             printf("The number is not in the list");
        else
             printf("The number is found");
    
        return 0;
    }
    Sample output: Enter the size of an array: 5 Enter the elements of the array: 4 6 8 0 3 Enter the number to be search: 0 The number is found

    1. Report
  7. Question:Write a simple code for binary search in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
        int a[10],i,n,m,c=0,l,u,mid;
    
        printf("Enter the size of an array: ");
        scanf("%d",&n);
    
        printf("Enter the elements in ascending order: ");
        for(i=0;i<n;i++){
             scanf("%d",&a[i]);
        }
    
        printf("Enter the number to be search: ");
        scanf("%d",&m);
    
        l=0,u=n-1;
        while(l<=u){
             mid=(l+u)/2;
             if(m==a[mid]){
                 c=1;
                 break;
             }
             else if(m<a[mid]){
                 u=mid-1;
             }
             else
                 l=mid+1;
        }
        if(c==0)
             printf("The number is not found.");
        else
             printf("The number is found.");
    
        return 0;
    }
    Sample output: Enter the size of an array: 5 Enter the elements in ascending order: 4 7 8 11 21 Enter the number to be search: 11 The number is found.

    1. Report
  8. Question:Write a simple code for binary search using function recursion in c programming language 

    Answer
    #include<stdio.h>
    int main(){
    
        int a[10],i,n,m,c,l,u;
    
        printf("Enter the size of an array: ");
        scanf("%d",&n);
    
        printf("Enter the elements of the array: " );
        for(i=0;i<n;i++){
             scanf("%d",&a[i]);
        }
    
        printf("Enter the number to be search: ");
        scanf("%d",&m);
    
        l=0,u=n-1;
        c=binary(a,n,m,l,u);
        if(c==0)
             printf("Number is not found.");
        else
             printf("Number is found.");
    
        return 0;
     }
    
    int binary(int a[],int n,int m,int l,int u){
    
         int mid,c=0;
    
         if(l<=u){
              mid=(l+u)/2;
              if(m==a[mid]){
                  c=1;
              }
              else if(m<a[mid]){
                  return binary(a,n,m,l,mid-1);
              }
              else
                  return binary(a,n,m,mid+1,u);
         }
         else
           return c;
    }
    Sample output: Enter the size of an array: 5 Enter the elements of the array: 8 9 10 11 12 Enter the number to be search: 8 Number is found.

    1. Report
  9. Question:C program for area of circle 

    Answer
    #include <stdio.h>
    #define PI 3.141
    int main(){
      float r, a;
      printf("Radius: ");
      scanf("%f", &r);
      a = PI * r * r;
      printf("%f\n", a);
      return 0;
    }

    1. Report
  10. Question:C program for area of a triangle 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
       
        float a,b,c;
        float s,area;
       
        printf("Enter size of each sides of triangle");
        scanf("%f%f%f",&a,&b,&c);
       
        s = (a+b+c)/2;
        area = sqrt(s*(s-a)*(s-b)*(s-c));
       
        printf("Area of triangle is: %.3f",area);
       
        return 0;
    }
    Sample output: Enter size of each sides of the triangle: 2 4 5 Area of triangle is: 3.800

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