Assignment II



Write a C program to do the following:
  1. Read two integers n and m as input. Output the value of nm without using the math library. Test your program with the following imputs: n=1, m=0; n=2, m=10; n=5, m=6.

  2. Read two integers n and m as input. Print the table of n starting from n*1 to n*m. So, if you have n=5 and m=10 as your inputs then your program should output
    5 
    10 
    15 
    20
    25
    30
    35
    40
    45
    50
    
  3. Read an integer n as input. Check whether n is prime or not? Your program should output "n is PRIME" or "n is NON-PRIME" as the case may be. For instance if the input is 7, your program should print: 7 is PRIME


    BONUS QUESTIONS (not to be evaluated as a component of this assignment)

  4. Write a C program to print out all Armstrong numbers between 1 and 500. If sum of the cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ).
  5. Write a C program to calculate the sum of all members of the arithmetic progression that contains 999 numbers beginning with -31. The difference of the progression is 7. Your program must obtain the result by direct summation. Then check the computed result using a general formula for the sum of an arithmetic progression.
  6. Write a C program that finds the largest among all the numbers upto the last input. The user has the flexibility to input the number one by one without any restriction. He/she can stop to input numbers at any time pressing a special key. Each time, a new number is read, the output displays the maximum upto that point.
    Sample output
    -------------
    Enter a number: 5
    output: MAX is 5
    DO U WANT TO QUIT (Type 0 to quit, 1 to continue): 1
    Enter a number:3
    output: MAX is 5
    DO U WANT TO QUIT (Type 0 to quit, 1 to continue): 1
    Enter a number:10
    output: MAX is 10
    DO U WANT TO QUIT (Type 0 to quit, 1 to continue): 0
    
  7. Read an integer n as input. Write a C progam to find all the prime factors of n. Hint: You might use the program for finding prime numbers that you wrote as a part of this assignment to solve this problem.
  8. The system of integers modulo 11, written Z/11, is a finite algebraic system consisting of the symbols 0, 1, 2, ... 10. Addition of a and b is defined by the rule "add a and b, then divide by 11 and take the remainder." Thus 5 + 9 ≡ 3 mod 11. Multiplication is defined by the rule "multiply a and b, then divide by 11 and take the remainder." Thus 2 * 9 ≡ 7 mod 11. Write a C program to compute the addition and multiplication tables for Z/11. For example the addition table should look like:
    + 0 1 2 3 4 5 6 7 8 9 10
    0 0 1 2 3 ...
    1 1 2 3 4 ...
    2 2 3 4 5 ...
    3 3 4 5 6 ...
    .
    .
    .
    10 10 0 1 2 ...