1. Question:Sum of digits in c using recursion 

    Answer
    #include<stdio.h>
    
    int getSum(int);
    int main(){
      int num,sum;
      printf("Enter a number: ");
      scanf("%d",&num);
    
      sum = getSum(num);
    
      printf("Sum of digits of number:  %d",sum);
      return 0;
    }
    
    int getSum(int num){
    
        static int sum =0,r;
    
        if(num!=0){
          r=num%10;
          sum=sum+r;
          getSum(num/10);
        }
    
        return sum;
    }
    Sample output: Enter a number: 45 Sum of digits of number: 9






    1. Report
  2. Question:How to calculate power of a number in c 

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






    1. Report
  3. Question:How to add two numbers without using the plus operator in c 

    Answer
    #include<stdio.h>
    
    int main(){
       
        int a,b;
        int sum;
    
        printf("Enter any two integers: ");
        scanf("%d%d",&a,&b);
    
        //sum = a - (-b);
        sum = a - ~b -1;
    
        printf("Sum of two integers: %d",sum);
    
        return 0;
    }
    Sample output: Enter any two integers: 5 10 Sum of two integers: 15






    1. Report
  4. Question:Write a c program or code to subtract two numbers without using subtraction operator 

    Answer
    #include<stdio.h>
    
    int main(){
       
        int a,b;
        int sum;
    
        printf("Enter any two integers: ");
        scanf("%d%d",&a,&b);
    
        sum = a + ~b + 1;
    
        printf("Difference of two integers: %d",sum);
    
        return 0;
    }
    Sample Output: Enter any two integers: 5 4 Difference of two integers: 1






    1. Report
  5. Question:Write a c program to find largest among three numbers using binary minus operator 

    Answer
    #include<stdio.h>
    int main(){
        int a,b,c;
        printf("\nEnter 3 numbers: ");
        scanf("%d %d %d",&a,&b,&c);
        if(a-b>0 && a-c>0)
             printf("\nGreatest is a :%d",a);
        else
             if(b-c>0)
                 printf("\nGreatest is b :%d",b);
             else
                 printf("\nGreatest is c :%d",c);
        return 0;
    }






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