Nothing Special   »   [go: up one dir, main page]

C Program Assignement

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 4

C PROGRAMMING ASSIGNMENTS

**********************************************************
Write C programs to perform the following:

(SIMPLE ARITHMETIC PROGRAMS)

1. Add two numbers.


2. Find out the area and perimeter of a rectangle.
3. Input three decimal numbers and find their sum and average.
4. Input two numbers and swap them –
a. Using a third variable
b. Without using a third variable
5. Input temperature in Celsius and convert it to Fahrenheit.

(IF-ELSE & IF-ELSE-IF LADDER)

6. Write a C program to input two numbers and find maximum between two numbers using conditional/ternary operator
7. Input a character and change its case. (lowercase to uppercase and vice versa).
8. Input a number and check whether it is odd or even and display accordingly.
9. Find the largest and smallest among three numbers supplied by user.
10. Check whether an input year is a leap year or not.

(OPERATORS & SWITCH-CASE)

11. Input two numbers and swap them using bitwise operators.
12. Convert an unsigned integer to its equivalent binary using bitwise operator.
13. Find the maximum of three numbers using ternary operator.
14. Implement simple arithmetic calculator using switch case.
15. Display the number of days for a given month.
E.g – User’s choice – 1. January, Output – 31,
2. February – Output – 28
(Need not consider leap
year)
16. Input a character from the user and check if it is a vowel or a consonant.

(LOOP CONTROL STRUCTURE)

17. Print the following patterns up to n no. of lines:

(a) *
**
***
****
(b) *
***
*****
*******

(c) *
***
*****
*******
***
*

(d)1
123
12345
1234567

18. Input two numbers and find their hcf and lcm.
19. Input a number and find the sum of its digits using while/do-while loop.
20. Input a number and check if it is a Palindrome number or not while/do-while loop.
21. Input a number and check if it is a prime number or not.
22. Input a number and check whether it is an Armstrong number or not using while/do-while loop.

(FUNCTIONS)

23. Input a number n and find its factorial using a user defined function long int fact(int)
24. Input a number and check if it a Krishnamurthy number.
25. Find the sum of first n prime numbers using as user defined function to check for prime. Input the value of n from
the user.
26. Input a limit n and print all prime fibonacci numbers up to n using a user defined function int prime(int) which
returns a 1 if the argument is a prime or else 0.
27. Input a limit n and print all twin prime numbers up to n.

(POINTERS & CALL BY ADDRESS)

28. Swap two numbers using call by address.


29. Find the sum and product of two numbers using call by address.
30. Input two sides of a rectangle and find their area and perimeter using call by address.
31. Find the lcm and hcf of two numbers using call by address.

(ARRAYS)

32. Write a C program to declare, initialize, input elements in array and print array.

33. Write a C program to find sum of all elements in an array

34. Write a C program to find maximum and Minimum element in an array


35. Write a C program to input elements in array and count negative elements in array.
36. Input a number and find its 2’s complement.
37. Input a decimal number and convert it into its equivalent binary.
38. Input a decimal number and convert it into its equivalent octal.
39. Input a decimal number and convert it into its equivalent hexadecimal.
40. Input a binary number and convert it into its equivalent decimal.
41. Perform any base to any base conversion.
42. Input an array of n elements remove all duplicate elements and print the new array.
43. Input an array of n elements in sorted order and perform binary search on it.
44. Write a C program to read elements in a matrix and find the sum of elements of each row and columns of matrix. C
program to calculate sum of rows and columns of matrix.
45.  Input a matrix of size (m x n), transpose it and print the final transposed matrix.
46. Input two matrices of any order and add them to produce a third matrix.
47. Input two matrices of any order and multiply them.
48. Input a matrix of size (m x n) and check whether it is a sparse matrix or not. A sparse matrix is a matrix where the
number of zero elements is greater than the number of non-zero elements.

(POINTER TO ARRAYS, ARRAY OF POINTERS & DYNAMIC ARRAYS)

49. Find the sum of the elements of an array using an user defined function int sum(int*,int). The function should accept
the array and the number of elements as arguments.
50. Sort an array of n elements using an user defined function int selection(int*,int), employing selection sort technique.
The function should accept the array and the number of elements as arguments.
51. Create a dynamic 1D array to store n elements and perform binary search on them.
52. Create a dynamic 2D array to store (m x n) elements and find its upper triangular matrix.

(STRINGS)

53. Implement strlen(), strcat(), strrev(), strcpy(), strcmp(), strcmpi() without using standard library functions.
54. Enter a sentence and find number of vowels, consonants, spaces and special characters.
55. Input a string that contains digits as well as characters. Find the sum of the digits.
56. Input a string and find sum of the ASCII values of all characters.
57. Input a string and check if it a palindrome or not.
58. Input a string and count the number of words in it.
59. Input a name and find its initial (e.g., Subhash Chandra Bose should be printed as S. C. B).
60. Input a string and delete all consecutive occurrences of characters.

(STRUCTURE, UNION, ENUM)

61. Write a C program to design a structure named XYZ with one integer and one float member. Declare 3 variables
V1, V2 and V3 of this structure. Input the values of members V1 and V2. Finally, add members of V1 and V2 and
keep the results in V3 and print it.

62. A student of honours class can have following attributes: roll (int), age (int), name (char []), sex (char), marks (int).
Write a program to input ‘n’ student records with the above attributes and find out how many of them are eligible to
vote. Also determine the 1st boy or girl (mention Mr. or Miss).

63. An angle is measured in degree and minutes. Write a program to specify a structure angle to measure an angle in
degree and minutes. Using a function angle sumangle (angle, angle), find the resultant angle after adding the two
angles and display the result with the help of the function void display (angle).

64. Accept two complex numbers and display their sum, difference and the modulus of the result after addition and
subtraction using the following specifications:
struct complex
{
float real, img;
};
complex sum (complex, complex);
complex difference (complex, complex);
void display modulus (complex);

RECURSION

65. Print the sum of natural numbers up to n using recursion.


66. Find the factorial of a number using recursion.
67. Find the nth Fibonacci number using recursion. The value of n should be taken as input.
68. Input two numbers and find their GCD using recursion.

(FILE HANDLING)

69. Input some numbers into a file and read them.


70. Input some characters from the user and write it in a file “one.txt” and read the characters from the file.
71. Copy one file to another.
72. Write a program that displays the program itself.

You might also like