0% found this document useful (0 votes)
34 views

Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Ahmedabad University

School of Engineering and Applied Science


Course: CSE100 Fundamentals of Computer Programming
Programming Assignment – 2

Instructions

 Use meaningful and descriptive variable/identifier names:


Good variable names (camelCase): rollNo, studentName, empSalary, salesPrice, taxRate,
 Every Program should have header with following information in comments
/*
Author : RollNo Firstname Lastname
Date : dd/mm/yyyy
Problem Definition : Program No. - write description about a program to be solved
*/
 Every Program should have footer with output of the Program in comments
/* Program Output */
 Submission details: Submit your assignment on lms.ahduni.edu.in before the given submission date. Create
one .ZIP file containing all C programs (.c files). Keep filename as RollNo-Name-Assignment2.zip. Keep your file
size less than 10MB.
 Programs submitted by a student should be the result of individual work based on his/her own efforts. Full or
part of the code should not be copied from internet or from peer students or other sources. A student should
not share/circulate the code/programs developed by them (for individual assignments) with their peers in any
form. Violation of above will be considered as academic dishonesty and any such case will be strictly dealt with
and liable to get zero in the evaluation.

Write a C program to solve the following problem definition:

1. Write a C program to read and print your name and address (Concept to learn: Getting
familiar with C Programming IDE, User input and output).
2. Write a C program to check whether a given number is divisible by 7 or not.
3. Write a C program to read a month number and print corresponding month name.
Sample output:
Enter Month Number: 1
January
4. Write a C program to input angles of a triangle and check whether triangle is valid or not.
5. Write a C program to check whether a person is eligible to vote or not.
6. Write a C program to Generate and print a Random Number.
7. Write a C program to Convert Celsius to Fahrenheit.
8. Write a C program to make a Simple Calculator.

Page 1
9. Write a C program to print the sum of first 10 numbers.
10. Write a C program to input 3 numbers from user and print the maximum among them.
(with conditional operator)
11. Write a program to find the sum of odd numbers and even numbers from 1 to N, N entered
by the user.
12. Create a converter that will convert a distance in meters to feet and inches.
Enter length in meters: 1
1.00m = 3 feet and 3.37 inches

Conversion formula:
1 feet = meters * 3.281
1 Feet = 12 inch

13. Write a program to read a character from the user and check whether it is a vowel (aeiou)
or consonant.
14. Write a program to check whether a character is uppercase or lowercase alphabet.
15. Write a program to accept two numbers and one mathematical operator. Using given
mathematical operator, calculate and display appropriate answer as shown below:
Sample output:
Enter first number : 5
Enter mathematical operator : +
Enter second number : 6
5 + 6 = 11
16. Write a program to enter a number from the user and display the sum of all the digits in the
number.
17. Accept a year from the user and check whether it is leap year or not.
The normal year contains 365 days but the leap year contains 366 days. This extra day is added to the
February month, that’s why we get February 29. All the years that are perfectly divisible by 4 are called as
Leap years except the century years. Century year’s means they end with 00 such as 1200, 1300, 2400, 2500
etc (Obviously they are divisible by 100). For these century years we have to calculate further to check the
Leap year.
- If the century year is divisible by 400 then that year is a Leap year
- If the century year is not divisible by 400 then that year is a Leap year

18. Write a program called ExtractDigits to extract each digit from an int in the reverse order. For
example, if the int is 12345, the output shall be "5 4 3 2 1", with a space separating the digits.

Page 2
19. Accept a number N from the user and print the first N elements of the Fibonacci series.
Hint: The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21
Fibonacci series is defined as a sequence of numbers in which the first two numbers are 1 and 1, or 0
and 1, depending on the selected beginning point of the sequence, and each subsequent number is
the sum of the previous two. So, in this series, the nth term is the sum of (n-1)th term and (n-2)th term.
Mathematically, the nth term of the Fibonacci series can be represented as:
tn = tn-1 + tn-2

20. Calculate the area of triangle given its three sides. The formula or algorithm used is:
Area = sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2 and a, b & c are
the sides of triangle.

21. Write a program that take input of 3 subjects marks out of 150. Count the percentage. Print
the Grade/Class based on following conditions:
 For 70% or more than 70% display DISTINCTION.
 For percentage between 60 and 69 display FIRST CLASS.
 For percentage between 50 and 59 display SECOND CLASS.
 For percentage between 40 and 49 display PASS CLASS.
 For percentage less than 40 display FAIL.
22. Considering three numbers provided by the user as length of sides of a triangle, first check, if
the values are valid for representing the sides of a triangle (i.e. whether a triangle can be
drawn using the given values). If the lengths of sides are valid, print the type of the triangle.

Hint: The sum of lengths of any two sides of a triangle is always greater than the length of
the third side. A triangle with all three sides having same length is known as an “Equilateral”
triangle. A triangle is called an “Isosceles” triangle if only two sides have equal lengths. If all
the sides of a triangle have different lengths, then it is called a “Scalene” triangle.

23. Write a C program to print following series using looping concept (use while or for loop).
i. 1, 2, 3, 4 ........ 100
ii. 100, 99, 98.......1
Page 3
iii. 1, 3, 5, 7........99
iv. 2, 4, 8, 16, 32, 64

24. Write a program to print following patterns. (hint: nested for loop)

(i) For N=4


A
BB
CCC
DDDD

(ii) For N=4,

(iii) For N=5

25. Write a C program to print 1-D array elements in reverse order.


26. Write a C program to check Identity Matrix.
27. Write a C program to find sum of diagonal elements of a given 3X3 matrix.
28. Write a C Program to delete duplicate array elements. [Use 1-D int array for implementing
your program]
29. Write a C program to perform addition of two 3X3 matrices.
30. Write a C program to perform multiplication of two 3X3 matrices.
31. Write a C program to find Maximum, Minimum and Average value from the given integer
array.
Page 4
32. Write a C function to find length of string.
33. Write a C function to check whether strings are same or not. The function should take two
string arguments to be compared.
34. Write a C function to convert given string into upper case.
35. Write a C program to copy content of source.txt file into destination.txt file. Create
source.txt file containing your roll-no and name.
36. Write a C program to count total number of vowels in a given text file.
37. Write a C program to compare content of two given files. Display appropriate message
“Content of files – Same” or “Content of files-not same”.
38. Write a C program to append content of file1 into file2.
39. Write a C program to accept integer values from keyboard. Transfer odd numbers to odd.txt
and even numbers to even.txt. Display data from both the files, also display even sum and
odd sum from respective files.
40. Write a C program to accept file names from command line arguments. Create a file copy
program using command line argument. (eg. mycopy mango.txt apple.txt) Here the
content of mango.txt must be copied to apple.txt.

*****

Page 5

You might also like