1. 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
  2. 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
  3. 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
  4. Question:Write a c program to find largest among three numbers using conditional operator 

    Answer
    #include<stdio.h>
    int main(){
      int a,b,c,big;
      printf("\nEnter 3 numbers:");
      scanf("%d %d %d",&a,&b,&c);
    
      big=(a>b&&a>c?a:b>c?b:c);
      printf("\nThe biggest number is: %d",big);
    
      return 0;
    }

    1. Report
  5. Question:C program for generic root 

    Answer
    #include<stdio.h>
    int main(){
    
    long int num,sum,r;
    printf("\nEnter a number:-");
    scanf("%ld",&num);
    
    while(num>10){
    sum=0;
    while(num){
    r=num%10;
    num=num/10;
    sum+=r;
    }
    if(sum>10)
    num=sum;
    else
    break;
    }
    printf("\nSum of the digits in single digit is: %ld",sum);
    return 0;
    }

    1. Report
  6. Question:C code for calculation of generic root in one line 

    Answer
    #include <stdio.h>
    int main(){         
    int num,x;
    printf("Enter any number: ");
    scanf("%d",&num);
    printf("Generic root: %d",(x=num%9)?x:9);
    return 0;
    }
    Sample output: Enter any number: 731 Generic root: 2

    1. Report
  7. Question:Prime factor of a number in c 

    Answer
    #include<stdio.h>
    int main(){
      int num,i=1,j,k;
      printf("\nEnter a number:");
      scanf("%d",&num);
      while(i<=num){
          k=0;
          if(num%i==0){
             j=1;
              while(j<=i){
                if(i%j==0)
                     k++;
                 j++;
              }
              if(k==2)
                 printf("\n%d is a prime factor",i);
          }
          i++;
       }
       return 0;
    }

    1. Report
  8. Question:Write a c program to find out NCR factor of given number 

    Answer
    #include<stdio.h>
    int main(){
      int n,r,ncr;
      printf("Enter any two numbers->");
      scanf("%d %d",&n,&r);
      ncr=fact(n)/(fact(r)*fact(n-r));
      printf("The NCR factor of %d and %d is %d",n,r,ncr);
      return 0;
    }
     int fact(int n){
      int i=1;
      while(n!=0){
          i=i*n;
          n--;
      }
      return i;
     }

    1. Report
  9. Question:How to convert string to int without using library functions in c programming language 

    Answer
    #include<stdio.h>
    
    int stringToInt(char[] );
    int main(){
      
        char str[10];
        int intValue;
    
        printf("Enter any integer as a string: ");
        scanf("%s",str);
    
       intValue = stringToInt(str);
    
        printf("Equivalent integer value: %d",intValue);
    
        return 0;
    }
    
    int stringToInt(char str[]){
        int i=0,sum=0;
    
        while(str[i]!='\0'){
             if(str[i]< 48 || str[i] > 57){
                 printf("Unable to convert it into integer.\n");
                 return 0;
             }
             else{
                 sum = sum*10 + (str[i] - 48);
                 i++;
             }
        }
        return sum;
    }
    Sample output: Enter any integer as a string: 123 Equivalent integer value: 123

    1. Report
  10. Question:Program in c to print 1 to 100 without using loop 

    Answer
    #include<stdio.h>
    
    int main(){
        int num = 1;
    
        print(num);
    
        return 0;
    }
    int print(num){
        if(num<=100){
             printf("%d ",num);
             print(num+1);
        }
    }
    Sample output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

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