C- Assignments


1.  Convert a temperature reading in degrees Fahrenheit to degrees Celsius, and vice versa using the formula :
C = (F-32) * 5/9
F = 9/5 * C + 32

2. Calculate the mass of air in an automobile tire, using the formula
PV = 0.37m(T+460)
where p= pressure, pounds per square inch(psi)
V = volume, cubic feet
m = mass of air, pounds
T= temperature, degrees Fahrenheit

The tire contains two cubic feet of air. Assume that the pressure is 32 psi at room temperature.

3. Calculate the cumulative product of a list of 'n' numbers. Try program for
(n=6): (6.2,12.3,5.0,18.8,7.1,12.8).

4. Calculate first 'n' prime numbers. (Accept 'n' from the user.)
     a. Find Twin prime nos. upto 'n'.
     b. Find first 'n' Twin prime nos.

5. Calculate the sum of first 100 odd integers.

6. Accept the name and 6 examination marks of the student. Calculate the average and determine the grade.

7. Write a C program that will allow the computer to be used as an ordinary desk calculator. Consider only the common arithmetic operations (+,-,*,/,%) Include a memory that can store one number.
      a. Using If
      b. Using If...Else
      c. Using Switch Case..
      d. Create a menu-driven program having options of the arithmatic          operator and then calculate the result.

8. Generate the following "pyramid" of digits, using nested loops.

            1
                       232
                      34543
                     4567654
                    567898765
                   67890109876
                  7890123210987
                 890123454321098
                90123456765432109
               0123456789876543210

Do not simply write out 10 multidigit strings. Instead, develop a formula to generate the appropriate output for each line.

9. Write an interactive C program that will convert a positive integer quantity to a roman numeral (eg. 12 will be converted to XII, 14 to XIV). Design the program so that it will execute repeatedly, until a value of zero is read in from the keyboard.

10. Write an interactive C program that will convert a date, entered in the form mm-dd-yy into an integer that indicates the number of days beyond January 1,1960.
(i) The day of the current year can be determined approx. as
      day = (int) (30.42 * (mm-1) ) + dd
(ii)  If mm ==2 (february), increase the value of day by 1.
(iii) If mm > 2 and mm<8 decrease the value of day by 1
(iv) If yy%4 == 0 and mm > 2 (leap year) increase the value of day by 1
(v) Increase the value of day by 1461 for each full four year cycle beyond 1-1-60.
(vi) Increase day by 365 for each additional full year beyond the completion fo the last full four year cycle, then add 1.


11. Consider the following foreign currencies and their equivalents to one U.S. dollar.

     British pound    :  0.6 pounds per U.S, dollar
     Canadian dollar  :  1.3 dollars per U.S. dollar.
     Dutch guilder    : 2.0 guilders per U.S. dollar
     French franc     :  6.0 frances per U.S. dollar
     Italian Lira     :  1250 lir per U.S. dollar
     Japanese yen     :  140 yen per U.S. dollar
     Mexican peso     :  1600 pesos per U.S. dollar
     Swiss franc      :  1.44 francs per U.S. dollar
     West German mark :  1.7 marks per U.S. dollar

Write an interactive, menu-driven program that will accept two different currencies and return the value of the second currency per one unit of the first currency. (For eg. if the two currencies are Japnese yen and Mexican pesos, the program will return the number of Mexican pesos equivalent to one Japanese yen.) Design the program so that it executes repetitiously, until an ending condition is selected from the menu.

12. Accept a 4 digit number and print whether it is palindrome or not.

13. Perform the following conversion
    To Decimal -
        a. octal equivlent. 
        b. Hexadecimal Equivalent
        c. Binary Equivalent

    To Binary -
        a. octal equivlent. 
        b. Hexadecimal Equivalent
        c. Decimal

14. Construct the following structure using loops
              ABCDEFGFEDCBA
              ABCDEF FEDCBA
              ABCDE   EDCBA
              ABCD     DCBA
              ABC       CBA
              AB         BA
              A           A

15. Write a program to determine and print the sum of the following harmonic series for a given value of n. (Accept value for 'n' from user)
1 + 1/2 + 1/3 +.....+ 1/n

16. Write a program to read the price of an item in decimal form (like 15.95) and print the output in paise (like 1595 paise)

17. The straight line method of computing the yearly depreciation of the value of an item is given by :
                      Purchase price - Salvage value     
depreciation =      ----------------------------------
                         Years of services
Write a program to determine the salvage value of an item when the purchase price, years of service, and the annual depreciation are given.

18. Write a program to calculate simple and compound interest.

19. Write a program to convert a given no. of days to a measure of time given in years, weeks and days. For eg. 375 days equals 1 year, 1 week and 3 days (Ignore leap year)

20. Write a program to find out the armstrong nos. between 1 to 999.
(Armstrong no. is the no whose sum of the cubes of the digits equals the number itself. 371 - (3*3*3) + (7*7*7) + (1*1*1) = 27+343+1 = 371.

21. The total difference travelled by a vehicle in t seconds is given by distance = ut + (a*t*t)/2 where u is the initial velocity (meters per second) a is the acceleration (meters/second square). Write a program to evaluate the distance travelled at regular intervals of time, given in the values of u and a. The program should provide flexibility to the user to select his own time intervals & repeat the calculations for different values of u and a.

22. Write a program to read the following nos., round them off to the nearest integer and print out the results in integer form : 35.7,50.21,-23.73,-46.45.

23. Print the Floyd's triangle
       1
       2 3
       4 5 6
       7 8 9 10
       11------15
(a) Modify to produce the following output
               1
               0 1
               1 0 1
               0 1 0 1
               1 0 1 0 1

24.Using for loops print the following outputs
(a)       *  (b)   * * * * *                (c)          1
         **          * * * *                     2 2
        ***            * * *                           3 3 3
       ****              * *                          4 4 4 4
      *****                *                         5 5 5 5 5

25. Accets a number 'n' and find the sum of the integers from 1 to 2, then from 1 to 3, then from 1 to 4 and so on untill it displays the sum of the integers from 1 to n. eg. if the input is 5, the output will be
1
3
6
10
15

27. Accept salary of an employee from user and print the denomination of notes required to pay the same.

28. Accept a maximum 4 digit no. and print it in words.
          eg.(1923 = one thousand nine hundred twenty three).

30. Calculate the perimeter of a rectangle.

31.Check whether entered integer is even or not by
      a. Using If
      b. Using Ternary Operator

32.Write a program that inputs two real numbers and tells whether product of the two numbers is
   a. equal to or greater than 100.
   b. greater than half of the first number.

33. Input 3 positive integers representing the sides of a triangle, determine whether they form a valid triangle. (The sum of any two sides must always be greater than the third side.)

34. Accept +ve and -ve nos from user till user enters 0. Calculate the total +ve and -ve nos.

35. Write a for loop to print out
         a. All even nos. from 1-100
         b. All odd nos. from 1-100

36. Write a program to calculate the average of n nos. with the value of 'n' entered by the user.

37. Write a program that allows any positive integer to be accepted. The program should count how many times the number has to be doubled before it reaches 1 million.

38. Calculate the sum of digits of a number entered by the user.

39. Print the following series upto n terms.. :
     a. 1 1 2 3 5 8....
     b. 1 2 2 4 8 32....
     c. 1 2 4 6 9 12 ....

40. Write programs using ALL THREE LOOPS to generate the following patterns :
     a. 1             b.  1        c.  4 3 2 1
        1 2          2 2               3 2 1
        1 2 3           3 3 3             2 1
        1 2 3 4       4 4 4 4           1

42. Accept 3 nos. from user and find the maximum and minimum using
        a. If
        b. If...else
        c. Ternary Operator

43. Accept two values and swap them :
     a. using temporary variable
     b. without using temporary variable

46. Using ALL THREE LOOP, write a program to print the ASCII values with     corresponding characters.

47.Accept a character and print whether it is a vowel or not.
     a. using if
     b. using if else..
     c. using switch case..

48. Accept a year from user and check whether it is leap year or not
     a. using if
     b. using if else..
     c. using ternary operator

49. Write a program that nearly prints a table of powers.
                    Table Of Powers
Integer    Square        3rd Power        4th Power     5th Power
-------   -------       ----------       -----------   -----------
    1     1             1                  1            1
    2        4             8                 16           32
    3        9            27                 81          243
    .
    .
    .

Strings
1. Read a five-letter word into the computer, then encode the word letter-by -letter by subtracting 30 from the numerical value that is used to represent each letter. Thus, if teh ASCII character set is being used the letter a (which is represented by the value 97) would become a C(represented by 67) and so on.

2. Read in a line of mixed text, store it in an appropriate array, and then write it out with all lowercase and uppercase letters reversed, all digits replaced by 0's, and all other characters (non-letters and non-digits) replaced by asterisks(*).

3. Write a C program that will enter a line of text, store it in an array, and then write it out backwards. Allow the length of the line to be unspecified (terminated by carriage return), but assume that it will not exceed 80 characters.

4. Write an interactive C program that will encode or decode a line of text. To encode the line of text, proceed as follows :
(i) Convert each character, including blank spaces, to its ASCII values.
(ii) Generate a positive random integer. Add this integer to the ASCII equivalent of each characxter. The same random integer will be used for the entire line of text.

5. Insert string in another. Accept two strings and the position where the second string will be inserted in first string.

6. Delete a part of a string. Accept the starting position and the number of characters to be deleted.

7. Write a program which will read a line of text & count all occurances of a particular word.

8. Accept a string and rewrite it in the alphabetical order.

9. Write a program to replace a particular word in a given string. eg. the word "PASCAL" should be replaced by 'C' in text :-
  "It is good to program in PASCAL language."

10. Write a program that replaces two or more consecutive blanks in a string mess by a single blank.

11. Write a program to check whether a given string is palindrome or not (Check for the cases RadAR and radar are palindrome)
  a. Using Array    b. Using Pointers

12. Write a program that will accept a line of English text and then print out the corresponding text in piglatin. A piglatin word is formed from English word by transporting first letter to the end of the word & then adding letter 'a' eg. "dog" will become "ogda".

13. Write a program that accepts a sring of n characters and exchanges the first character with the last, the second last with the next to last, and so on.. until n exchanges have been made.
       a. Write using the function also.

14. Write a function that, given two strings a and b, returns the position at which a occurs in b. For eg. if a is "cat" and b is "concatenate", the value returned is 4, since the substring "cat" is found starting at the fourth character of "concatenate" If a does not occur in b, the value zero should be returned.

Functions

1. Write a function day_name that receives a number n & returns  pointer to a character string containing the name of the corresponding day. The day name should be kept in a static table of character strings local to the function.

2. Write a program to computes and prints a factorials of a number using recursion.

3. Write a function that will scan a character string passed as an argument & convert all lower case characters into their upper case equavalents and vice versa using :
        (a) Call by Value method.
        (b) Call by Reference method.

4. Write a function that will find out mean of the integer array and is passed as a parameter to function. (Write Pointer Version Only.)

5. Write a program to reverse the string stored in the following array of pointers to strings :
char *s[] = {
              "Welcome",
              "to",
              "Pgdcm examination !"
            } ;
The program should contain a function strrev (string) which should reverse the contents of string. Call this function for reversing each string stored.

6. Write a program that calls a function insert() which inserts a character in a string. Function should take string, character to be inserted, position of insertion.

7. Write a function that is passed an array, the array's length & a constant value. The role of the function is to multiply each element of the array by the constant.

8. Write a program that includes a recursive function.
The Legendre polynomials can be calculated by means of the following formulas P 0 = 1, P1 = x,
Pn= [ (2n-1)/n] * Pn-1 - [(n-1)/]pn-2
where n=2,3,4..... & x is an floating point no. between 1 & 1.5.

9. Write a function to calculate the roots of a quadratic qeuation of the form : ax2 + bx + c = 0.

10. Write a program to obtain the sum of the first 10 terms of the following series using recursion :

           x3            x5         x7          x9
      x - ---     +     ----    -  ---      +  ---- - .....
           3!            5!         7!          9!

11. Write a function that is passed an array and a constant, and counts how many elements of the array are less than the constant, equal to it, and greater than it.

12. Write the simulation for the following library functions :
     Maths.h
      a. Find the absolute value
      b. Find the ceiling value
      c. Find the floor value  
      d. Find the power of the value
      e. Find the exponential
      f. Find the square root
      g. Find the length of string
      h. Reverse the string
      i. Copy the String
      j. Copy no. of characters from the string
      k. Concatenate the String
      l. Concatenate no. of characters from the String
      m. Compare the two strings
      n. Compare the two strings ignoring the case.
      o. Search specified character in the string
      p. Search specified string in the string
      q. Convert entered string to lower case
      r. Convert entered string to upper case
      s. Set all characters to character specified
      t. Set specified no. of characters to character specified.

13. Using recursion, solve the following series :
     a. 1 1 2 3 5 8....
     b. 1 2 2 4 8 32....
     c. 1 2 4 6 9 12 ....

14. Input a date and check in function whether it is valid or not.

15. Input account no., name, previous amount, amount, tr.type(D/W) and in     function calculate the net amount and return it to main().

16. Write the following functions :
    a. Count the no. of vowels in a string : vcount()
    b. Count the number of words in a string : wcount()
    c. Find the length of a string    : len()
    d. Convert string to uppercase : tocaps()
     e. Convert string to lowercase : tosmall()
    f. Convert the first character of each word to uppercase : proper()
    g. Find the position of substring in string : pos()
    h. Accept two strings and comapre them : comp()
    i. Copy one string to another : copy()
    j. Extract specified no. of chars. from a string : substr()


17. Accept value for 'n' from user. Write a program to computes the sum of the first 'n' positive integers through recursion.

18.The greatest common divisor of two positive integers is the largest integer that is a divisor of both of them. For eg. 3 is the GCD of 6 and 15, and 1 is the GCD of 15 and 22. Write a recursive function that computes the GCD of two positive integers.


Arrays
1.Accept values into an array of 10 elements. Find the total of all even and odd positions in the array.

2.Accept values into an array of 10 elements. Find out the total number of occurance of maximum number in the array.

3.Write a program to find out the second largest number in an array of 10 elements.

4. Sort an array using
     (a) Selection Sort
     (b) Bubble Sort
     (c) Insertion Sort

5. Accept values in two integer arrays of 5 elements each. Sort both arrays and store result in third array of 10 elements in sorted order.
(Note Third array should not be sorted seperately)

6.Accept values in 3-3 matrix. Write a program for its transpose.(ie. rows as columns and columns as rows)

7. Write a program to accept value in two 3-3 matrices and multiply them.

8. Write a program to accept values in two 3-3 matrices and swap them.

9. Write a program that reads in an two dimensional array of nos., calculates and displays the row & column sums as well as the grand total.

10. Write a program that will initialize the 2 dimensional array A of size n*n as follows :
All diagonal elements are initialized to 1 and others to 0.

11. Search an inputed numeric element in an array and print its position.

12.


Pointers
1. Write a program using pointers to read in an array of integers & print its elements in reverse order.

2. Using pointers write a function that receives a character string and a character as argument and deletes all occurances of this character in the string. The function should return the corrected string with no holes.

3. Copy string using pointers.

4. Write a program using pointer to function which calculates total sum as well as avg. values of 1st// ten nos.

Structures
1. Define a structure that will describe a hotel. It should have members that include the name, address, grade, average room charge and number of rooms.
Write a function to perform the following operations :
 (a) To print out hotels of a given grade in order of charges.
 (b) To print out hotels with room charges less tha
n a given value.

2. Accept the employee details of 10 employees in structure emp. The details are empno, empname, designation,dept,basic.
Print the details in tabular form with net salary (Basic + Da - HRA)


File Handling & Command Line Arguments:
1. Write a programm to create file and display contents in reverse order.

2. Accept filename from user and count the following :
     a.  No. Of Characters        b. No. Of Lines
     c.  No. Of Words          d. No. Of Tabs

3. Write a program to copy one file to another. Accept file names from user.

4.Write a program to encrypt file contents by replacing each character in   file by next character in alphabetical set.

5.Accept source and target filenames from user. Change case of each character while copying source file to target file.

6. Write a program to find a character in a file and replace it by a specified character.

7. Write a program to simulate the following DOS commands with appropriate checks.
   a. copy  <file> to <file1>  
   b. type  <file>
   c. copy a.txt + b.txt   c.txt
   d. Rename <file> <file1>
   e. delete <file1>

8. Two files DATA1 & DATA2 contain sorted lists of integers.
Write a program to produce a third file DATA which holds a single sorted, merged list of these two lists. Use command line arguments to specify the file names.

9. Write a program to calculate average length of a line in given text file.

10. Write a program that will exchange the contents of the two files without using third file. Assume that files are of equal length.

11. Write a program which prints out only those lines from a file which are containing more than 80 characters. Also print out the line number of these lines.

12. Read a file and display it
       a. Line by line.          b. Page by page

After each line / page ask user to view next line/page?

13. Write a program that declares a structure with elements like emp.name, telephone no., hours worked, hourly wages. Accept the data into the structure and write data on file called "MYEMP.DAT" till the user enters "NO"
(Accept answer 'Y' or 'N' from user before accepting next record.).

14. Write a program which will remove all comments from a C program. The program should be capable of removing comments which occur at the beginning of a statement, at the end of a statement, as well as the comments which are split over multiple lines.

15. Accept a string from user, accept an constant integer value and encrypt     the string by adding that no. to each character.

16. Write a line editor.

17. Accept a filename from user and print the size of the file.

18. Write a program of palindrome through command line argument.

19. Create a text file using command line argument. Save the file when user presses '*'

20.Create a menu driven program :
      1. Data Entry
      2. Report
      3. Exit

For option 1 :  Input Book Code, Name, Author, Price. If price < 200 give 10% discount else 12% disc. Calculate net price of book and write all details in "Book.Dat" file.

For Option 2 : Display all the records page wise on screen.

21. Accept a text file name from user and calculate the occurance of each alphabet in that text file. For eg.

A    B   C     D    E    F   G   H   .....
80  30   45   17   15   68  56   87  .....

22. Write a program to check the proper pairing of braces. The program should have two variables, one to keep track of left braces, and the other to keep track of right braces. And the end of the process, both the variables should have the same values. If not, and the value for left braces variable is larger than the right, then a message stating that many }'s are missing should be displayed for eg.
ERROR : Missing right braces : }}}

23. Extend the above program to deal with both braces '{}' and parentheses '()' simultaneously.

24. The ancient Egyptians wrote in hieroglyphics. In this system of writing, vowel sounds are not representd, only consonans. Is written Englis generally understandable vowels? To experiement, write a function is_vowel() that returns 1 if a letter is a vowel and 0 otherwise. Use your function in a program that reads the standard input file and writes to the standard output file, deleting all vowels. Use redirection on a file containing some English text to test your program.

25. Write a program to number the lines in a file. The input file name should be passed to the program as a command line argument. The program should write to stdout. Each line in the input file should be written to the output file with the line number and a space prepended.

26. Write a program that displays one or more files given as command line arguments. Also allow a command line option specifying the number of lines that are to be displayed per page.



TOTAL   197-