Sample Questions and answers

  1. Program to find whether the character is lower case or upper case
    #include <stdio.h>
     int main()
    {
         int islow (char); 
         char chr; 
         printf ("Enter a character 
    "); 
         scanf ( "%c", &chr); 
         if (islow(chr))
            printf ("The character is of lower case
    ");
         else
             printf ("The character is of upper case
    "); 
    }
    
    int islow (char ch)
    {
        if (ch >= 97 && ch < = 122)
           return (1);
        else
          return (0);
    }
    
  2. Program to determine if a character is alphabetic
    #include <stdio.h> 
    int main () 
    {
        int chr;
        int is_alpha (char); 
        printf ("Enter the character...
    "); 
        scanf ("%c",&chr); 
        if (is_alpha (chr))
           printf ("The character is alphabetic 
    ");
        else
           printf ("The character is not alphabetic 
    ");	
    }
    
    int is_alpha (char ch)
    {
        if ((ch >= 'a" && ch <= 'z") || (ch >= 'A" && ch <= 'Z"))
          return (1);
        else
           return (0);
    }
    
  3. Function to find sum and difference of two numbers
    #include <stdio.h> 
    int main ()
    {
        int sum (int, int); 
        int diff (int, int);
        int num1, num2; 
        int add_result, diff_result; 
        printf ("Enter any two numbers 
    "); 
        scanf ( "%d%d", &num1, &num2) ; 
        add_result = sum (num1, num2); 
        diff_result = diff (num1, num2);
        printf ("The sun of two numbers is %d
    ", add_result);
        printf ("The difference between two numbers is %d
    ", diff_result);
    }
    
    int sum (int n1, int n2)
    {
        int res; 
        res = n1 + n2; 
        return (res); 
    }
    
    int diff (int n1, int n2)
    { 
        int res; 
        res = n1 - n2;
        return(res);
    }
    
  4. Program to find the sum of digits of a number
    #include <stdio.h>
     int main ()
    {
        int sum of digit (int);
        int num, sum;
        printf("Enter the number
    ");
        scanf("%d", &num); 
        sum = sum_of_digit (num); 
        printf ("The sum of individual digits of a number in %d", sum);
    }
    
    int sum_of_digit(int n)
    {
        float digit;
        int count = 0;
        int s = 0;
        while (n! = 0)
        {
    	digit = n % 10;
            count ++; 
            s = s + digit;
            n = n / 10;
        }
    printf ("The number of digits in the number = %d
    ", count);
    return(s);
    }