Home
Diploma Practice C Online People
Certificate Contact Us

Assignments on If and Switch statements


1. Read an integer number from the user and print whether the number is 
   even number or odd number. Check the first bit (0th bit), if first bit 
   is one, the number is odd, else number is even

2. Read an integer number from the user and print whether the number is 
   even number or odd number. Find the remainder value when the given 
   number is divided by 2. If remainder is zero, the number is even. 
   Else number is odd.

3. Read an integer number from the user and print whether the number is 
   negative or positive. Find the number as negative or positive by checking
   the most significant bit. That is bit 31. If bit 31 is one, it is 
   negative number. Else positive number.

4. Read a character from the user, and print whether the character is
   Capital letter / Small letter / Numeric digit / Other.

5. Read a character from the user. If character is capital letter, convert
   it to small letter and print it. If character is small letter, convert it
   to capital letter. If character is nither capital nor small letter, print
   as it is.

6. Write a program to perform divisibility test. Read two numbers from the
   user. Test if first number is divisible by second number without any
   remainder. Based on the resule, print "Divisible Test Passed" or 
   "Divisible test failed". 

7. Read two integer numbers from the user. Print the bigger number. If both 
   numbers are equal, print "Both numbers are equal\n".

8. Read three integer numbers from the user. If these three numbers are
   in asending order, print "Asending". If the numbers are in decending order 
   print "Decending". If all three numbers are equal print "Equal". If none
   of the above are true, print "Random".

9. Read the radius of a sphere in centimeters from the user. Ask the user
   to enter the metal type of sphere as below:
   printf("1:Aluminum  2:Copper  3:Gold  4:Iron   5:Silver\n");
   Read the metal type as number 1 to 5. If user enters invalid metal number
   print error and exit from the program.
   Calculate and print the weight of sphere by using following densities of
   metals:
    Aluminum       2.712 grams/cm3 (grams per centimeter cube)
    Copper         8.940
    Gold          19.320
    Iron           7.850
    Silver        10.490

10. Read two integer numbers from the user. Ask the user to enter any
    arithmetic operator character. User can enter any one of the following
    arithmetic operator character:
    +  -  *  /  %
    Based on the character do the corresponding operation on the numbers and
    print the result. Use If-elseIf-elseIf statement.

11. Redo the above program by using switch() statement.

12. Read month from the user as integer. User should enter 1 for the month
    January, 2 for February and so on. The program should print the number
    days in the given month. Use switch() statement. Assume that year is
    not a leaf year.

13. Redo the above program. Now read both month and year from the user.
    Print the number of days in the given month. Assume that year is leaf
    year if remainder is zero when devided by 4.





#401, Sai Sushma Homes, 23/A, S.R. Nagar Main Road, Hyderabad-500038, India.
Ph: +91-40-48508764, 7702028989, depik.help@gmail.com