119
Beginning Programming in C Documentation Release 1.0 Rishi Agrawal <[email protected]> Sep 11, 2017

Release 1.0 Rishi Agrawal

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Release 1.0 Rishi Agrawal

Beginning Programming in CDocumentation

Release 1.0

Rishi Agrawal <[email protected]>

Sep 11, 2017

Page 2: Release 1.0 Rishi Agrawal
Page 3: Release 1.0 Rishi Agrawal

Contents

1 Basics of Variables, Functions and Operators 11.1 asg_a2300 : Number - Add 5 and 6. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 asg_a2301 : Number - Add two numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 asg_a2303 : Number - Find the product of 200 and 3. . . . . . . . . . . . . . . . . . . . . . . . . . . 31.4 asg_a0008 : Number - Find the sum of 5 numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 asg_a0017 : Number - Find the profit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.6 asg_a0031 : Number - Find the gross salary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.7 asg_a0032 : Number - Convert Kms to Meters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.8 asg_a0034 : Number - Convert KMs to MilliMeters. . . . . . . . . . . . . . . . . . . . . . . . . . . 71.9 asg_a0045 : Number - Find the volume of a cube. . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.10 asg_a0011 : Number - Sum of the digits of a 5 digit number. . . . . . . . . . . . . . . . . . . . . . . 81.11 asg_a0012 : Number - Product of digits of a 5 digit number. . . . . . . . . . . . . . . . . . . . . . . 91.12 asg_a0006 : Number - Calculate the amount after adding the simple interest. . . . . . . . . . . . . . 101.13 asg_a0010 : Number - Reverse a 5 digit integer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.14 asg_a0938 : Number - Make number from 5 digits. . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.15 asg_a0042 : Number - Rotate by 3 places for a 5 digit number. . . . . . . . . . . . . . . . . . . . . . 13

2 Decision Making 152.1 asg_a3000 : Decision - Rotate by 3 places for a 5 digit number. . . . . . . . . . . . . . . . . . . . . 152.2 asg_a3001 : Decision - Reverse a 5 digit integer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.3 asg_a3002 : Decision - Product of digits of a 5 digit number. . . . . . . . . . . . . . . . . . . . . . . 172.4 asg_a3003 : Decision - Sum of the digits of a 5 digit number. . . . . . . . . . . . . . . . . . . . . . 182.5 asg_a3004 : Decision - Find the profit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.6 asg_a3005 : Decision - Find the gross salary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.7 asg_a3006 : Decision - Find the volume of a cube. . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.8 asg_a0044 : Decision - Check palindrome of a 5 digit number. . . . . . . . . . . . . . . . . . . . . . 212.9 asg_a0048 : Decision - Dispute - Cuboid longest diagonal . . . . . . . . . . . . . . . . . . . . . . . 222.10 asg_a0122 : Decision - Find if profit was made in a sale. . . . . . . . . . . . . . . . . . . . . . . . . 232.11 asg_a0123 : Decision - Find maximum of 3 values. . . . . . . . . . . . . . . . . . . . . . . . . . . . 242.12 asg_a0124 : Decision - Find minimum among 5 values. . . . . . . . . . . . . . . . . . . . . . . . . 252.13 asg_a0128 : Decision - Check for zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262.14 asg_a0129 : Decision - Find maximum in 4 numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 272.15 asg_a0130 : Decision - Find the grade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282.16 asg_a0908 : Decision - Check if number is multiple of 3 . . . . . . . . . . . . . . . . . . . . . . . . 292.17 asg_a0909 : Decision - Check if a number is divisible by 6 . . . . . . . . . . . . . . . . . . . . . . . 302.18 asg_a0940 : Decision - Check if a number is odd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

i

Page 4: Release 1.0 Rishi Agrawal

2.19 asg_a0941 : Decision - Check if a number is even . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.20 asg_a0942 : Decision - Check if divisible by 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.21 asg_a0943 : Decision - Check divisible by 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.22 asg_a0945 : Decision - Check even digits in a 5 digit number. . . . . . . . . . . . . . . . . . . . . . 342.23 asg_a2202 : Decision - Find max of two numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.24 asg_a2203 : Decision - Find the maximum of three numbers. . . . . . . . . . . . . . . . . . . . . . . 362.25 asg_a0043 : Decision - Find the length of a number . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3 Loops 393.1 asg_a0275 : Loop - Write a function print_pattern_02() which prints the pattern. . . . . . . . 393.2 asg_a0276 : Loop - Write a function print_pattern_03() which prints the pattern. . . . . . . . 403.3 asg_a0277 : Loop - Write a function print_pattern_04() which prints the pattern. . . . . . . . 413.4 asg_a0278 : Loop - Write a function print_pattern_05() which prints the pattern. . . . . . . . 423.5 asg_a0279 : Loop - Write a function print_pattern_05() which prints the pattern. . . . . . . . 433.6 asg_a0280 : Loop - Write a function print_pattern_06() which prints the pattern. . . . . . . . 443.7 asg_a0281 : Loop - Write a function print_pattern_07() which prints a pattern. . . . . . . . . 453.8 asg_a0282 : Loop - Write a function print_pattern_08() which prints a pattern. . . . . . . . . 463.9 asg_a0283 : Loop - Write a function print_pattern_10() which prints the pattern. . . . . . . . 473.10 asg_a0284 : Loop - Write a function print_pattern_11() to print the pattern. . . . . . . . . . 483.11 asg_a0664 : Loop - Write a program to find all the prime numbers in a range of 1 to N. . . . . . . . . 493.12 asg_a0665 : Loop - Write a function to find the factorial of a given number. . . . . . . . . . . . . . . 493.13 asg_a0823 : Loop - Write a program for calculating the factorial of a number . . . . . . . . . . . . . 503.14 asg_a0824 : Loop - Write a function to calculate pow(x,n)? . . . . . . . . . . . . . . . . . . . . . . 513.15 asg_a0827 : Loop - How to generate fibonacci numbers? How to find out if a given number is a

fibonacci number or not? Write C programs to do both. . . . . . . . . . . . . . . . . . . . . . . . . . 523.16 asg_a0834 : String - Write a function to convert from decimal to binary. . . . . . . . . . . . . . . . . 533.17 asg_a0836 : Loop - Write a function to find the GCD of two numbers. . . . . . . . . . . . . . . . . . 543.18 asg_a0864 : Loop - Write a function to round numbers. . . . . . . . . . . . . . . . . . . . . . . . . 553.19 asg_a0865 : Loop - How can we sum the digits of a given number in single statement? . . . . . . . . 563.20 asg_a0870 : Loop - How to generate prime numbers? How to generate the next prime after a given

prime? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573.21 asg_a2246 : Loop - Sum of even terms in fibnocci series . . . . . . . . . . . . . . . . . . . . . . . . 573.22 asg_a2247 : Loop - nth prime number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583.23 asg_a2424 : Loop - Reverse a number with any number of digits. . . . . . . . . . . . . . . . . . . . 593.24 asg_a2425 : Loop - Count the odd numbers in the even places. . . . . . . . . . . . . . . . . . . . . . 603.25 asg_a0041 : Loop - Left Rotate a 5 digit number by n places. . . . . . . . . . . . . . . . . . . . . . 613.26 asg_a0126 : Loops - is_prime() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623.27 asg_a0853 : Loops - Write a function to check if a given year is a leap year or not? . . . . . . . . . . 633.28 asg_a0274 : Loop - Write a function print_pattern_01() which prints pattern. . . . . . . . . 643.29 asg_a0944 : Loop - Count the odd digits in a number. . . . . . . . . . . . . . . . . . . . . . . . . . 64

4 Arrays 674.1 asg_a0651 : Array - Find the product of all the elements stored in the array? What can be the possible

problems here. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674.2 asg_a0652 : Array - Find the maximum and minimum element of an array . . . . . . . . . . . . . . 684.3 asg_a0654 : Array - Find the median of the array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694.4 asg_a0655 : Array - Find element occuring maximum number of times. . . . . . . . . . . . . . . . . 704.5 asg_a0656 : Array - Fill an array with the multiples of 3, then remove the numbers which are divisible

by 5. Fill the empty spaces so generated with -1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.6 asg_a0657 : Array - Find an array with random elements . . . . . . . . . . . . . . . . . . . . . . . . 724.7 asg_a0803 : Array - Find the Prime numbers using Sieve of Eratosthenes. . . . . . . . . . . . . . . . 734.8 asg_a0890 : Array - Find out 1500th ugly number . . . . . . . . . . . . . . . . . . . . . . . . . . . 734.9 asg_a2207 : Array - Perform sum and multiplication of multiple elements in a array/list/vector. . . . 744.10 asg_a2245 : Array - Sum of multiples of 3 or 5 below 1000 . . . . . . . . . . . . . . . . . . . . . . 75

ii

Page 5: Release 1.0 Rishi Agrawal

4.11 asg_a2422 : Array - Find element occuring minimum times . . . . . . . . . . . . . . . . . . . . . . 764.12 asg_a2210 : Array - Check for value in given array. . . . . . . . . . . . . . . . . . . . . . . . . . . . 774.13 asg_a0923 : String - Convert a decimal to hexadecimal. . . . . . . . . . . . . . . . . . . . . . . . . 784.14 asg_a0927 : String - Convert a hexadecimal to decimal. . . . . . . . . . . . . . . . . . . . . . . . . 794.15 asg_a0928 : String - Convert a hexadecimal to octal. . . . . . . . . . . . . . . . . . . . . . . . . . . 794.16 asg_a0929 : String - Convert a decimal to binary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804.17 asg_a0930 : String - Convert a binary to decimal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814.18 asg_a0931 : String - Convert a hexadecimal to binary. . . . . . . . . . . . . . . . . . . . . . . . . . 824.19 asg_a0932 : String - Convert a binary to hexadecimal. . . . . . . . . . . . . . . . . . . . . . . . . . 834.20 asg_a0933 : String - Convert a binary to octal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 834.21 asg_a0934 : String - Convert a octal to binary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

5 Strings 875.1 asg_a0001 : String - Change the case of a sentance. . . . . . . . . . . . . . . . . . . . . . . . . . . . 875.2 asg_a0003 : String - Program to have alternate case in a string, like “hElLoWoRlD” . . . . . . . . . 885.3 asg_a0004 : String - Find the lowercase characters in a string. . . . . . . . . . . . . . . . . . . . . . 895.4 asg_a0007 : String - Find the upper case characters in a string. . . . . . . . . . . . . . . . . . . . . . 905.5 asg_a0013 : String - Toggle the case of all the charcters in a string. . . . . . . . . . . . . . . . . . . 915.6 asg_a0016 : String - Function to check if character is a consonant . . . . . . . . . . . . . . . . . . . 925.7 asg_a0154 : String - Design a algorithm to rotate a string. . . . . . . . . . . . . . . . . . . . . . . . 935.8 asg_a0669 : String - write a function to convert the epoch to date. . . . . . . . . . . . . . . . . . . . 945.9 asg_a0753 : String - Insert the word “Hello” in the middle. of the words in an sentence. . . . . . . . 955.10 asg_a0873 : String - Write a function to remove all the spaces from a string. . . . . . . . . . . . . . 965.11 asg_a0935 : String - Add two Hex Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975.12 asg_a0936 : String - Add two Octal Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985.13 asg_a0937 : String - Add two binary numbers which are stored as strings. . . . . . . . . . . . . . . . 995.14 asg_a2204 : String - Find the length of a string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995.15 asg_a2205 : String - Check character for vowel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1005.16 asg_a2208 : String - Reverse a string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1015.17 asg_a2209 : String - Check a string for palindrome. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025.18 asg_a2212 : String - Generate n times a character . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035.19 asg_a2218 : String - Check palindrome phrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.20 asg_a2219 : String - Check pangram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055.21 asg_a2223 : String DISPUTE - Caesar Cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.22 asg_a2236 : String - Print the frequency of characters in a file. . . . . . . . . . . . . . . . . . . . . . 1075.23 asg_a2238 : String - Find words with occurences as 1 . . . . . . . . . . . . . . . . . . . . . . . . . 1085.24 asg_a2254 : String - Change the case of a sentance. . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

6 2 D Arrays 111

7 File Handling 113

iii

Page 6: Release 1.0 Rishi Agrawal

iv

Page 7: Release 1.0 Rishi Agrawal

CHAPTER 1

Basics of Variables, Functions and Operators

asg_a2300 : Number - Add 5 and 6.

Description

Write a function add_5_6() to add 5 and 6 and return the output.

Samples

Number Explanation Input Output1 Basic test for the function. 11

Function

Function Signature

int add_5_6(void)

Function Arguments

Number Type Name Explanation Remarks1 void Nothing to be passed.

Return Value

Number Type Name Explanation Remarks1 int NA Sum of 5 and 6.

1

Page 8: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

int add_5_6(void) {

// Write the function body here.

}

asg_a2301 : Number - Add two numbers.

Description

Write a function add_two_numbers() which takes two numbers as input from the user and prints the sum to thescreen.

Samples

Number Explanation Input Output1 Check for positive numbers. [5, 6] 112 Check for negative number. [5, -6] -1

Function

Function Signature

int add_two_numbers(int num1, int num2)

Function Arguments

Number Type Name Explanation Remarks1 num1 int First number to be added.1 num2 int Second number to be added.

Return Value

Number Type Name Explanation Remarks1 int NA Nothing to be returned.

Function Placeholder

int add_two_numbers(int num1, int num2) {

// Write the function body here.

}

2 Chapter 1. Basics of Variables, Functions and Operators

Page 9: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a2303 : Number - Find the product of 200 and 3.

Description

Write a function find_product_200_and_3() to find the product of 200 and 3

Samples

Number Explanation Input Output1 600

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0008 : Number - Find the sum of 5 numbers.

Description

Write a function sum_of_5_numbers() to find the sum of 5 numbers passed to the function.

Samples

Number Explanation Input Output1 [1, 2, 3, 4, 5] 15

1.3. asg_a2303 : Number - Find the product of 200 and 3. 3

Page 10: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int sum_of_5_numbers(int a, int b, int c, int d, int e)

Function Arguments

Number Type Name Explanation Remarks1 int a The first number.2 int b The second number.3 int c The third number.4 int d The fourth number.5 int e The fifth number.

Return Value

Number Type Name Explanation Remarks1 int NA The sum of the 5 numbers passed.

Function Placeholder

int sum_of_5_numbers(int a, int b, int c, int d, int e) {

// Write the function body here.

}

asg_a0017 : Number - Find the profit.

Description

Write a function get_profit() which when passed the cost price and the profit percentage, returns the profit.Ignore the decimal points.

Samples

Number Explanation Input Output1 Check if function is working correctly. [1000, 20] 200

Function

Function Signature

int get_profit(int cp, int profit)

4 Chapter 1. Basics of Variables, Functions and Operators

Page 11: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 int cp The cost price of the product.2 int profit The profit percentage of the product.

Return Value

Number Type Name Explanation Remarks1 int NA Nothing to be returned.

Function Placeholder

int get_profit(int cp, int profit) {

// Write the function body here.

}

asg_a0031 : Number - Find the gross salary.

Description

Write a function calculate_gross_salary() which when passed the Basic salary, Dearness Allowance inpercentage of Basic and House Rent Allowance in rupees, calculates and returns the gross salary, which is the sum ofall three.

Samples

Number Explanation Input Output1 Check if function is proper [20000, 10, 5000] 27000

Function

Function Signature

int calculate_gross_salary(int basic_salary, int dearness_allowance, inthouse_rent)

Function Arguments

Number Type Name Explanation Remarks1 int basic_salary Basic Salary in Rupees2 int dearness_allowance Dearness Allowance in percentage of Basic3 int house_rent House Rent Allowance in Rupees

1.6. asg_a0031 : Number - Find the gross salary. 5

Page 12: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 int NA Calculated Gross Salary

Function Placeholder

int calculate_gross_salary(int basic_salary, int dearness_allowance, int house_rent) {

// Write the function body here.

}

asg_a0032 : Number - Convert Kms to Meters.

Description

Write a function convert_kms_to_mts() which takes as input KMs and returns the converted value in Meters.Your function will not be tested for zero or negative values.

Samples

Number Explanation Input Output1 Check for basic functionality. [1000] 10000002 Check for negative numbers. [-1000] -10000003 Check for 0. 0 0

Function

Function Signature

int convert_kms_to_mts (int kms)

Function Arguments

Number Type Name Explanation Remarks1 int kms KMs to be converted to meters.

Return Value

Number Type Name Explanation Remarks1 int NA Return the KMs in meters.

6 Chapter 1. Basics of Variables, Functions and Operators

Page 13: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

int convert_kms_to_mts (int kms) {

// Write the function body here.

}

asg_a0034 : Number - Convert KMs to MilliMeters.

Description

Write a function convert_kms_to_mms() which when passed value in KMs returns values in MilliMetres. Yourfunction will not be tested for negative values.

Samples

Number Explanation Input Output1 Check for basic functionality [1] 10000002 Check for negative values [-1] -10000003 Check for zero 0 0

Function

Function Signature

int convert_kms_to_mms(int kms)

Function Arguments

Number Type Name Explanation Remarks1 int kms KMs to convert to MilliMeters.

Return Value

Number Type Name Explanation Remarks1 int NA Return in milli meters

Function Placeholder

int convert_kms_to_mms(int kms) {

// Write the function body here.

}

1.8. asg_a0034 : Number - Convert KMs to MilliMeters. 7

Page 14: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0045 : Number - Find the volume of a cube.

Description

Write a function volume_cube() which when passed the side of a cube, returns the volume of the cube.

Samples

Number Explanation Input Output1 Check for basic values. 5 125

Function

Function Signature

int cube_volume(int side)

Function Arguments

Number Type Name Explanation Remarks1 int side Integer based on which the volume will be calculated.

Return Value

Number Type Name Explanation Remarks1 int NA Volume of the cube.

Function Placeholder

int cube_volume(int side) {

// Write the function body here.

}

asg_a0011 : Number - Sum of the digits of a 5 digit number.

Description

Write a function sum_of_5_digits() which takes an integer and returns the sum of the numbers. Your functionwill not be tested for the numbers which is less than zero, zero, or less than 5 digits.

8 Chapter 1. Basics of Variables, Functions and Operators

Page 15: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check if function is proper for 3 digits. 12345 15

Function

Function Signature

int sum_of_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number whose digits are to be added.

Return Value

Number Type Name Explanation Remarks1 int NA Sum of all the digits.

Function Placeholder

int sum_of_5_digits(int number) {

// Write the function body here.

}

asg_a0012 : Number - Product of digits of a 5 digit number.

Description

Write a function product_of_5_digits() which returns the products of the digits passed to the function. Yourfunction will not be checked for negative numbers or numbers with zeros. Your function will not be checked fornumbers less than 5 digits.

Samples

Number Explanation Input Output1 Check if function is proper 12345 120

1.11. asg_a0012 : Number - Product of digits of a 5 digit number. 9

Page 16: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int product_of_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number whose digits are to be multiplied.

Return Value

Number Type Name Explanation Remarks1 int NA Product of all the digits.

Function Placeholder

int product_of_5_digits(int number) {

// Write the function body here.

}

asg_a0006 : Number - Calculate the amount after adding the simpleinterest.

Description

Write a function get_si_amount() which will take principle, rate of interest, and time in years and return theamount. Ignore decimal values.

Notes

Note 1

This is a general note.

Samples

Number Explanation Input Output1 See if the function works correctly for simple inputs. [10000, 5, 2] 110002 See if it works for 0% interest [1000, 0, 2] 10003 See if it works for 0 Months [1000, 5, 0] 1000

10 Chapter 1. Basics of Variables, Functions and Operators

Page 17: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int get_si_amount (int principle, int rate, int years)

Function Arguments

Number Type Name Explanation Remarks1 int principle Principle amount to be used for calculation2 int rate Rate percentage to be used for calculation3 int years Number of years to be used for calculation

Return Value

Number Type Name Explanation Remarks1 int NA Calculated amount

Function Placeholder

int get_si_amount (int principle, int rate, int years) {

// Write the function body here.

}

asg_a0010 : Number - Reverse a 5 digit integer.

Description

Write a function reverse_5_digit_int() which takes an integer and returns the reverse of it. Your functionwill not be tested for number less than zero and numbers ending with zeros.

Samples

Number Explanation Input Output1 Check if function is properly working for a random integer. 12345 54321

Function

Function Signature

int reverse_5_digit_int(int number)

1.13. asg_a0010 : Number - Reverse a 5 digit integer. 11

Page 18: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 int input Number to be reversed.

Return Value

Number Type Name Explanation Remarks1 int NA Returned the reversed number.

Function Placeholder

int reverse_5_digit_int(int number) {

// Write the function body here.

}

asg_a0938 : Number - Make number from 5 digits.

Description

Write a function make_number_from_5_digits() which will be passed 5 integers. The function needs to makea number out of them. For example the numbers passed will be 1, 2, 3, 4, 5 and the output will be 12345.

Samples

Number Explanation Input Output1 [1, 2, 3, 4, 5] 12345

Function

Function Signature

int make_number_from_5_digits(int a, int b, int c, int d, int e)

Function Arguments

Number Type Name Explanation Remarks1 a First digit2 b Second digit3 c Third digit4 d Fourth digit5 e Fifth digit

12 Chapter 1. Basics of Variables, Functions and Operators

Page 19: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 int NA Number made from the passed values.

Function Placeholder

int make_number_from_5_digits(int a, int b, int c, int d, int e) {

// Write the function body here.

}

asg_a0042 : Number - Rotate by 3 places for a 5 digit number.

Description

Write a function rotate_left_3_5_digits() which takes input a number and rotates the number to the left by3 digits. Your function will not be checked against a negative number, a number with zeros.

Samples

Number Explanation Input Output1 Check if function is proper 12345 45123

Function

Function Signature

int rotate_left_3_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number to be rotated.

Return Value

Number Type Name Explanation Remarks1 int NA Rotated number.

Function Placeholder

1.15. asg_a0042 : Number - Rotate by 3 places for a 5 digit number. 13

Page 20: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

int rotate_left_3_5_digits(int number) {

// Write the function body here.

}

14 Chapter 1. Basics of Variables, Functions and Operators

Page 21: Release 1.0 Rishi Agrawal

CHAPTER 2

Decision Making

asg_a3000 : Decision - Rotate by 3 places for a 5 digit number.

Description

Write a function rotate_left_3_5_digits() which takes input a number and rotates the number to the left by3 digits. Incase the number passed is negative you should return -2. Incase there is an error in input and you cannotproceed, return -1. If the number is having zeros in 10s place, return -3.

Samples

Number Explanation Input Output1 Check if function is proper 12345 451232 Return -1 for numbers less then 5 digits. 123 -13 Return -1 for numbers more than 5 digits. 123456 -14 Check if the 4th digit is zero. 12306 -35 Check for negative numbers. -12345 -2

Function

Function Signature

int rotate_left_3_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number to be rotated.

15

Page 22: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 int NA Rotated number.

Function Placeholder

int rotate_left_3_5_digits(int number) {

// Write the function body here.

}

asg_a3001 : Decision - Reverse a 5 digit integer.

Description

Write a function reverse_5_digit_int() which takes an integer and returns the reverse of it. The functionshould return -1 for the numbers which is not of 5 digits. The function should return -2 for the numbers ending with 0.

Samples

Number Explanation Input Output1 Check if function is properly working for a random integer. 12345 543212 Check for less than 5 digits. 1234 -13 Check for more than 5 digits. 123456 -24 Check if the number contains 0. 12340 -3

Function

Function Signature

int reverse_5_digit_int(int number)

Function Arguments

Number Type Name Explanation Remarks1 int input Number to be reversed.

Return Value

Number Type Name Explanation Remarks1 int NA Returned the reversed number.

16 Chapter 2. Decision Making

Page 23: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

int reverse_5_digit_int(int number) {

// Write the function body here.

}

asg_a3002 : Decision - Product of digits of a 5 digit number.

Description

Write a function product_of_5_digits() which returns the products of the digits passed to the function. If anyof the digits in the number is 0 then return -2. If the number is not of 5 digits return -1. For negative values the functionshould return negative product.

Samples

Number Explanation Input Output1 Check if function is proper 12345 1202 Check for negative values. -12345 -1203 Check the working if one of the digits is 0. 12340 -24 Check the working if the number passed in not 5 digits. 1234 -15 Check the working if the number passed in not 5 digits. 123456 -1

Function

Function Signature

int product_of_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number whose digits are to be multiplied.

Return Value

Number Type Name Explanation Remarks1 int NA Product of all the digits.

Function Placeholder

2.3. asg_a3002 : Decision - Product of digits of a 5 digit number. 17

Page 24: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

int product_of_5_digits(int number) {

// Write the function body here.

}

asg_a3003 : Decision - Sum of the digits of a 5 digit number.

Description

Write a function sum_of_5_digits() which takes an integer and returns the sum of the numbers. If any of thedigits is 0 then return -1. If the number of digits is not 5 return -2.

Samples

Number Explanation Input Output1 Check if function is proper for 5 digits. 12345 152 Check if function works properly when one digit is 0. 12340 -13 Check if function works properly when one digit is 0. 12305 -14 Check if function works properly when one digit is 0. 12045 -15 Check if function works properly when one digit is 0. 10345 -16 Check if function is proper for 5 digits. 1234 -27 Check if function is proper for 5 digits. 123456 -2

Function

Function Signature

int sum_of_5_digits(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number whose digits are to be added.

Return Value

Number Type Name Explanation Remarks1 int NA Sum of all the digits.

Function Placeholder

int sum_of_5_digits(int number) {

// Write the function body here.

18 Chapter 2. Decision Making

Page 25: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

}

asg_a3004 : Decision - Find the profit.

Description

Write a function get_profit() which when passed the cost price and the profit percentage, returns the profit.Ignore the decimal points. If the cp is 0 then return -1. If the profit is 0 then return -2. If both cp and profit are 0 thenreturn -3.

Samples

Number Explanation Input Output1 Check if function is working correctly. [1000, 20] 2002 Check if function is working correctly. [0, 20] -13 Check if function is working correctly. [1000, 0] -24 Check if function is working correctly. [0, 0] -3

Function

Function Signature

int get_profit(int cp, int profit)

Function Arguments

Number Type Name Explanation Remarks1 int cp The cost price of the product.2 int profit The profit percentage of the product.

Return Value

Number Type Name Explanation Remarks1 int NA Nothing to be returned.

Function Placeholder

int get_profit(int cp, int profit) {

// Write the function body here.

}

2.5. asg_a3004 : Decision - Find the profit. 19

Page 26: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a3005 : Decision - Find the gross salary.

Description

Write a function calculate_gross_salary() which when passed the Basic salary, Dearness Allowance inpercentage of Basic and House Rent Allowance in rupees, calculates and returns the gross salary, which is the sum ofall three. If the basic is 0 then return -1, if the DA is 0 then return -2, if the HRA is 0 then return -3, if all the three arezero then return -4.

Samples

Number Explanation Input Output1 Check if function is proper [20000, 10, 5000] 270002 Check if function is proper [0, 10, 5000] -13 Check if function is proper [20000, 0, 5000] -24 Check if function is proper [20000, 10, 0] -35 Check if function is proper [0, 0, 0] -4

Function

Function Signature

int calculate_gross_salary(int basic_salary, int dearness_allowance, inthouse_rent)

Function Arguments

Number Type Name Explanation Remarks1 int basic_salary Basic Salary in Rupees2 int dearness_allowance Dearness Allowance in percentage of Basic3 int house_rent House Rent Allowance in Rupees

Return Value

Number Type Name Explanation Remarks1 int NA Calculated Gross Salary

Function Placeholder

int calculate_gross_salary(int basic_salary, int dearness_allowance, int house_rent) {

// Write the function body here.

}

20 Chapter 2. Decision Making

Page 27: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a3006 : Decision - Find the volume of a cube.

Description

Write a function volume_cube() which when passed the side of a cube, returns the volume of the cube. If the sidegiven is less than 0 return -1.

Samples

Number Explanation Input Output1 Check for basic values. 5 1252 Check if cube is given a side with negative length. -5 -1

Function

Function Signature

int cube_volume(int side)

Function Arguments

Number Type Name Explanation Remarks1 int side Integer based on which the volume will be calculated.

Return Value

Number Type Name Explanation Remarks1 int NA Volume of the cube.

Function Placeholder

int cube_volume(int side) {

// Write the function body here.

}

asg_a0044 : Decision - Check palindrome of a 5 digit number.

Description

Write a function is_5_digit_palindrome_number() which when passed a number checks if the number ispalindrome or not and returns True (0) or False (1). For any errors return -1. Note that you have to find out the caseswhere your input might break.

2.7. asg_a3006 : Decision - Find the volume of a cube. 21

Page 28: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check if function is proper [12321] 02 Check if function is proper for negative [-12321] -13 Check if the function returns error for numbers ending with zero. [64] -1

Function

Function Signature

int is_5_digit_palindrome_number(int num)

Function Arguments

Number Type Name Explanation Remarks1 int num Input number to check for palindrome

Return Value

Number Type Name Explanation Remarks1 int NA 0 for True and 1 for False.

Function Placeholder

int is_5_digit_palindrome_number(int num) {

// Write the function body here.

}

asg_a0048 : Decision - Dispute - Cuboid longest diagonal

Description

Write a function calculate_longest_diagonal() which when passed the length, breadth and height of thecube returns the length of the longest diagonal of the cuboid.

Notes

Note 1

This is sample note.

22 Chapter 2. Decision Making

Page 29: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check if function is proper [10, 4, 5] 11.87

Function

Function Signature

int calculate_longest_diagonal(int side1, int side2, int side3)

Function Arguments

Number Type Name Explanation Remarks1 int side1 First side of the cuboid.2 int side2 Second side of the cuboid.3 int side3 Third side of the cuboid.

Return Value

Number Type Name Explanation Remarks1 int NA Length of the longest diagonal of the cuboid.

Function Placeholder

int calculate_longest_diagonal(int side1, int side2, int side3) {

// Write the function body here.

}

asg_a0122 : Decision - Find if profit was made in a sale.

Description

Write a function is_profit() which when passed the SP and CP, returns if there was a profit made in the sale. Ifthere is a profit return success else return failure. In case no profit or loss was made return -1.

Samples

Number Explanation Input Output1 Check if function is proper [200, 100] 12 Check if function is proper [100, 100] 03 Check if function is proper [99, 100] -1

2.10. asg_a0122 : Decision - Find if profit was made in a sale. 23

Page 30: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int is_profit(int selling_price, int cost_price)

Function Arguments

Number Type Name Explanation Remarks1 selling_price float Selling price of the article.2 cost_price float Cost price of the article.

Return Value

Num-ber

Type Name Explanation Re-marks

1 int NA Return value based on the result obtained. If there is a profit return >0, for noprofit no loss return 0, for loss return -1

Function Placeholder

int is_profit(int selling_price, int cost_price) {

// Write the function body here.

}

asg_a0123 : Decision - Find maximum of 3 values.

Description

Write a function maximum_in_3() which when passed three numbers returns the value which is the maximum.

Samples

Number Explanation Input Output1 If first is maximum. [30, 5, 20] 302 If second is maximum. [10, 50, 20] 503 If third is maximum. [10, 5, 200] 2004 If first is not maximum and others are equqal. [1, 5, 5] -15 If second is not maximum and other are equal. [20, 5, 20] -26 If third is not maximum and other are equal. [10, 10, 5] -37 If all three are equal. [10, 10, 10] -4

24 Chapter 2. Decision Making

Page 31: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int my_maximum(int num1, int num2, int num3)

Function Arguments

Number Type Name Explanation Remarks1 int num1 The first number.2 int num2 The second number.3 int num3 The third number.

Return Value

Number Type Name Explanation Remarks1 int NA The number which is maximum.

Function Placeholder

int my_maximum(int num1, int num2, int num3) {

// Write the function body here.

}

asg_a0124 : Decision - Find minimum among 5 values.

Description

Write a function my_minimum() which when passed three numbers returns the one which is the minimum.

Samples

Number Explanation Input Output1 Check if function is proper [10, 5, 20] 52 Check if function is proper [10, -5, 20] -53 Check if function is proper [0, 0, 0] 0

Function

Function Signature

int my_minimum(int num1, int num2, int num3)

2.12. asg_a0124 : Decision - Find minimum among 5 values. 25

Page 32: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 int num1 The first number.2 int num2 The second number.3 int num3 The third number.

Return Value

Number Type Name Explanation Remarks1 int NA The number which is minimum.

Function Placeholder

int my_minimum(int num1, int num2, int num3) {

// Write the function body here.

}

asg_a0128 : Decision - Check for zero

Description

Write a function is_zero() which checks if the number is zero or not.

Samples

Number Explanation Input Output1 Check if function is proper [0] 02 Check if function is proper [10] 1

Function

Function Signature

int is_zero(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number to be worked upon.

26 Chapter 2. Decision Making

Page 33: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 int NA 1/0 based on the result.

Function Placeholder

int is_zero(int number) {

// Write the function body here.

}

asg_a0129 : Decision - Find maximum in 4 numbers

Description

Write a function find_maximum_in_4() which finds the maximum out of the 4 numbers passed to it.

Samples

Number Explanation Input Output1 Check if function is proper [20, 10, 5, 1] 202 Check if function is proper [20, 30, 5, -21] 303 Check if function is proper [-20, -10, 0, -21] 04 Check if function is proper [-20, -10, -5, 21] 21

Function

Function Signature

int find_maximum_in_4 (int num1, int num2, int num3, int num4)

Function Arguments

Number Type Name Explanation Remarks1 int num1 First number2 int num2 Second number3 int num3 Third number4 int num4 Fourth number

Return Value

Number Type Name Explanation Remarks1 integer NA The maximum of the four numbers passed.

2.14. asg_a0129 : Decision - Find maximum in 4 numbers 27

Page 34: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

int find_maximum_in_4 (int num1, int num2, int num3, int num4) {

// Write the function body here.

}

asg_a0130 : Decision - Find the grade

Description

Write a function find_grade() which will take marks as input and return a number based on the grade obtained.Grade can be calculated as follows

Grade 1 - above 80 Grade 2 - above 60 less than equal to 80 Grade 3 - above 40 less than equal to 60 Grade 4 - above20 less than equal to 40 Grade 5 - above 00 less than equal to 20 Grade 6 - equal to 0

If the marks is more than 100 or is invalid, return -1.

Samples

Number Explanation Input Output1 Check if function is proper [85] 12 Check if function is proper [80] 23 Check if function is proper [65] 24 Check if function is proper [60] 35 Check if function is proper [45] 36 Check if function is proper [40] 47 Check if function is proper [25] 48 Check if function is proper [20] 59 Check if function is proper [15] 510 Check if function is proper [110] -111 Check if function is proper [-1] -112 Check if function is proper [0] 6

Function

Function Signature

int find_grade(int marks)

Function Arguments

Number Type Name Explanation Remarks1 integer marks The marks of which the grade needs to be found.

28 Chapter 2. Decision Making

Page 35: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 integer NA The Grade to be returned based on the calculations mentioned.

Function Placeholder

int find_grade(int marks) {

// Write the function body here.

}

asg_a0908 : Decision - Check if number is multiple of 3

Description

Write a function is_multiple_of_3() to check whether a given unsigned number is a multiple of 3, withoutusing division and modulo operators.

Samples

Number Explanation Input Output1 Check if the function is proper [3] 02 Check if the function is proper [5] -13 Check if the function is proper [-5] -14 Check if the function is proper [-6] 0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

2.16. asg_a0908 : Decision - Check if number is multiple of 3 29

Page 36: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0909 : Decision - Check if a number is divisible by 6

Description

Write a function is_divisible_by_6() which checks if a number is divisible by 6 or no.

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

30 Chapter 2. Decision Making

Page 37: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0940 : Decision - Check if a number is odd.

Description

Write a function check_if_odd() to check if a number is odd or no.

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0941 : Decision - Check if a number is even

Description

Write a function is_even() to check if a number is even or no.

Samples

Number Explanation Input Output1 #

2.18. asg_a0940 : Decision - Check if a number is odd. 31

Page 38: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0942 : Decision - Check if divisible by 3

Description

Write a function divisible_by_3() to check if a number is divisible by 3.

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

32 Chapter 2. Decision Making

Page 39: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0943 : Decision - Check divisible by 5

Description

Write a function is_divisible_by_5() which returns if a number is divisible by 5.

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

2.21. asg_a0943 : Decision - Check divisible by 5 33

Page 40: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0945 : Decision - Check even digits in a 5 digit number.

Description

Write a function count_even_digits() which will count the number of even digits in a 5 digit number.

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

34 Chapter 2. Decision Making

Page 41: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a2202 : Decision - Find max of two numbers.

Description

Define a function mymax() that takes two numbers as arguments and returns the largest of them. Use the if-then-elseconstruct available in your language.

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output1 Test if the function can find the maximum. [5, 6] 62 Test the function behaviour when same values are passed. [5, 5] 5

Function

Function Signature

int mymax(int num1, int num2)

Function Arguments

Number Type Name Explanation Remarks1 int num1 The first number.2 int num2 The second number.

Return Value

Number Type Name Explanation Remarks1 int NA The larger number.

Function Placeholder

int mymax(int num1, int num2) {

// Write the function body here.

}

2.23. asg_a2202 : Decision - Find max of two numbers. 35

Page 42: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a2203 : Decision - Find the maximum of three numbers.

Description

Samples

Number Explanation Input Output1 First input is maximum. [7, 6, 5] 72 Middle one is the maximum. [5, 7, 6] 73 Last on is the maximum. [5, 6, 7] 74 Check for negative numbers. [-5, -6, -7] -55 All equal. [5, 5, 5] 5

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0043 : Decision - Find the length of a number

Description

Write a function numlen() which when passed a number returns the number of digits in the number.

36 Chapter 2. Decision Making

Page 43: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check if function is proper [1234] 42 Check if function is proper for negative [-1234] 43 Check if function is proper [0] 0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

2.25. asg_a0043 : Decision - Find the length of a number 37

Page 44: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

38 Chapter 2. Decision Making

Page 45: Release 1.0 Rishi Agrawal

CHAPTER 3

Loops

asg_a0275 : Loop - Write a function print_pattern_02() whichprints the pattern.

Description

***************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

39

Page 46: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0276 : Loop - Write a function print_pattern_03() whichprints the pattern.

Description

***************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

40 Chapter 3. Loops

Page 47: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0277 : Loop - Write a function print_pattern_04() whichprints the pattern.

Description

HELLOXHELLOHELLO HELLOHELL ELLOHEL LLOHE LOH OHE LOHEL LLOHELL ELLOHELLO HELLOHELLOXHELLO

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

3.3. asg_a0277 : Loop - Write a function print_pattern_04() which prints the pattern. 41

Page 48: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0278 : Loop - Write a function print_pattern_05() whichprints the pattern.

Description

####*###**##***#*********

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

42 Chapter 3. Loops

Page 49: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0279 : Loop - Write a function print_pattern_05() whichprints the pattern.

Description

******

*********

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

3.5. asg_a0279 : Loop - Write a function print_pattern_05() which prints the pattern. 43

Page 50: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0280 : Loop - Write a function print_pattern_06() whichprints the pattern.

Description

**************** ********* ******* ***** *** *** ***** ******* ********* ****************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

44 Chapter 3. Loops

Page 51: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0281 : Loop - Write a function print_pattern_07() whichprints a pattern.

Description

*********

********************************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

3.7. asg_a0281 : Loop - Write a function print_pattern_07() which prints a pattern. 45

Page 52: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0282 : Loop - Write a function print_pattern_08() whichprints a pattern.

Description

*************************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

46 Chapter 3. Loops

Page 53: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0283 : Loop - Write a function print_pattern_10() whichprints the pattern.

Description

*************************

********

****************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

3.9. asg_a0283 : Loop - Write a function print_pattern_10() which prints the pattern. 47

Page 54: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0284 : Loop - Write a function print_pattern_11() to printthe pattern.

Description

******************

***************************

******************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

48 Chapter 3. Loops

Page 55: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0664 : Loop - Write a program to find all the prime numbers ina range of 1 to N.

Description

Write a function generate_numbers() which will generate numbers from 1 to N and print it on the screen.

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0665 : Loop - Write a function to find the factorial of a givennumber.

Description

Write a function find_factorial(number) which taked a positive integer as input and returns the factorial ofthat number.

3.11. asg_a0664 : Loop - Write a program to find all the prime numbers in a range of 1 to N. 49

Page 56: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Notes

Note 1

null

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0823 : Loop - Write a program for calculating the factorial of anumber

Description

Write a function calculate_factorial() which calculates the factorial of a passed number.

50 Chapter 3. Loops

Page 57: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check for a simple case. 3 62 Check for corner case 1. 1 13 Check for corner case 0. 0 1

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0824 : Loop - Write a function to calculate pow(x,n)?

Description

Write a function find_pow(x,n) which takes a number and the power to be calculated and returns the result of xto the power n

Samples

Number Explanation Input Output1 Check if function is proper [2, 2] 42 Check if function is proper [5, 3] 1253 Check if function is proper for negative power [8, -1] 0.125

3.14. asg_a0824 : Loop - Write a function to calculate pow(x,n)? 51

Page 58: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0827 : Loop - How to generate fibonacci numbers? How to findout if a given number is a fibonacci number or not? Write Cprograms to do both.

Description

Write a function gen_fibboniaci() which generates fibbonicai numbers till the number passed.

Samples

Number Explanation Input Output1 5 [1, 1, 2, 3]2 5 [1, 1, 2, 3]

Function

Function Signature

void alter_case_1(char *str)

52 Chapter 3. Loops

Page 59: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0834 : String - Write a function to convert from decimal to bi-nary.

Description

Write a function convert_base(decimal_number, base) to convert the input decimal number to any of thebase that is specified from Octal(8), Binary(2) or Hexadecimal(16)

Samples

Number Explanation Input Output1 Check if function is proper for binary [8, 2] 10002 Check if function is proper for octal [30, 8] 363 Check if function is proper for hexadecimal [400, 16] 190

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

3.16. asg_a0834 : String - Write a function to convert from decimal to binary. 53

Page 60: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0836 : Loop - Write a function to find the GCD of two numbers.

Description

Write a function find_gcd(num1, num2) which takes two number as input and calculate and return the GCD.

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

54 Chapter 3. Loops

Page 61: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0864 : Loop - Write a function to round numbers.

Description

Write a function round_number(double number) which takes input a double type number and returns therounded number.

Samples

Number Explanation Input Output1 Check if the function is proper [16.34] 162 Check if the function is proper [16.57] 173 Check if the function is proper [-20.51] -19

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

3.18. asg_a0864 : Loop - Write a function to round numbers. 55

Page 62: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0865 : Loop - How can we sum the digits of a given number insingle statement?

Description

Write a function sum_number_digits(int number) which takes input an int type number and returns the sumof the digits of that number. You need to write the function in such a way that the whole calculation is done within asingle statement only.

Samples

Number Explanation Input Output1 Check if the function is proper [123] 62 Check if the function is proper [-123] 63 Check if the function is proper [0] 0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

56 Chapter 3. Loops

Page 63: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0870 : Loop - How to generate prime numbers? How to gener-ate the next prime after a given prime?

Description

Write a function generate_prime(int prime_number) which takes input a prime number and returns thenext prime number after that input number. If input number is not a prime, return 0.

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a2246 : Loop - Sum of even terms in fibnocci series

Description

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. Write a function which returns the sum of the

3.20. asg_a0870 : Loop - How to generate prime numbers? How to generate the next prime after agiven prime?

57

Page 64: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

even numbers in the Fibonacci series under a number specefied in the function call. The function name should befind_even_numbers_fibonacci().

Samples

Number Explanation Input Output1 #

Function

Function Signature

int find_even_numbers_fibonacci(int n)

Function Arguments

Number Type Name Explanation Remarks1 int int The highest number till which we have to find the fibonacci terms.

Return Value

Number Type Name Explanation Remarks1 int NA The result value.

Function Placeholder

int find_even_numbers_fibonacci(int n) {

// Write the function body here.

}

asg_a2247 : Loop - nth prime number

Description

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. Write a functionfind_nth_prime().

Samples

Number Explanation Input Output1 #

58 Chapter 3. Loops

Page 65: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

long long find_nth_prime(int n)

Function Arguments

Number Type Name Explanation Remarks1 int n The nth prime number to be found out.

Return Value

Number Type Name Explanation Remarks1 long long NA The value of the nth prime number.

Function Placeholder

long long find_nth_prime(int n) {

// Write the function body here.

}

asg_a2424 : Loop - Reverse a number with any number of digits.

Description

Write a function find_occured_min(int arr) to find the element which has occurred for the minimum num-ber of times in an array. Return 0 if the array is empty. Return 1 if all the numbers have appeared equal times.

Samples

Number Explanation Input Output1 Check for a general case. [1, 2, 2, 4, 4] 12 Check when zero as an input number [1, 2, 0, 4] 13 Check for empty array [] 0

Function

Function Signature

void alter_case_1(char *str)

3.23. asg_a2424 : Loop - Reverse a number with any number of digits. 59

Page 66: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a2425 : Loop - Count the odd numbers in the even places.

Description

Write a function count_odd_at_even() which gives the number of odd digits which are there at even positions.

Samples

Number Explanation Input Output1 Check for a general case. [1, 2, 2, 4, 4] 12 Check when zero as an input number [1, 2, 0, 4] 13 Check for empty array [] 0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

60 Chapter 3. Loops

Page 67: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0041 : Loop - Left Rotate a 5 digit number by n places.

Description

Write a function rotate_numbers() which when passed a number rotates left the number by n places.

Notes

Note 1

null

Samples

Number Explanation Input Output1 Check if function is proper [12345] 234512 Check if function is proper for negative [-12345] -234513 Check if function is proper [23145] 314524 Check if function is proper [234567891] 345678912

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

3.25. asg_a0041 : Loop - Left Rotate a 5 digit number by n places. 61

Page 68: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0126 : Loops - is_prime()

Description

Write a function is_prime(number) which finds if a number is prime or not.

Samples

Number Explanation Input Output1 Check if function is proper [3] True2 Check if function is proper [10] False3 Check if function is proper [-3] False4 Check if function is proper [0] False

Function

Function Signature

int is_prime(int number)

Function Arguments

Number Type Name Explanation Remarks1 int number Number to be checked for prime.

Return Value

Num-ber

Type Name Explanation Re-marks

1 int NA Return value based on if a number is prime or no. 1 if passed number isprime, 0 otherwise.

Function Placeholder

int is_prime(int number) {

// Write the function body here.

}

62 Chapter 3. Loops

Page 69: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0853 : Loops - Write a function to check if a given year is a leapyear or not?

Description

Write a function is_leap_year(int year) to check if the valid year passed to the function is a leap year or not.Leap year is a year which has 366 days instead of 365 days in a year. The function should return True if the year is aleap year, else it should return False. In case of invalid input, it should return False.

Samples

Number Explanation Input Output1 Check if the function is proper [2016] True2 Check if the function is proper [-2016] False3 Check if the function is proper [2017] False

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

3.27. asg_a0853 : Loops - Write a function to check if a given year is a leap year or not? 63

Page 70: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0274 : Loop - Write a function print_pattern_01() whichprints pattern.

Description

****************************************

Samples

Number Explanation Input Output

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0944 : Loop - Count the odd digits in a number.

Description

Write a function count_odd_digits(). Return the number of digits which are odd.

64 Chapter 3. Loops

Page 71: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 #

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

3.29. asg_a0944 : Loop - Count the odd digits in a number. 65

Page 72: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

66 Chapter 3. Loops

Page 73: Release 1.0 Rishi Agrawal

CHAPTER 4

Arrays

asg_a0651 : Array - Find the product of all the elements stored in thearray? What can be the possible problems here.

Description

Write a function product_of_array(int arr) which multiplies all the elements of the array and returns themultiplied result value. The function takes a 2D array as input. Return 0 if the array is empty.

Samples

Number Explanation Input Output1 Check for a general case. [10, 20, 2, 4] 16002 Check when zero as an input number [10, 20, 0, 4] 03 Check for empty array [] 0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

67

Page 74: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0652 : Array - Find the maximum and minimum element of anarray

Description

Write a function find_min_max(int arr) which returns the minimum and maximum element contained in a2D array. An integer array is passed as input to the function. Return 0 if the array is empty.

Samples

Number Explanation Input Output1 Check for a general case. [10, 20, 2, 4] [2, 20]2 Check when zero as an input number [10, 20, 0, 4] [0, 20]3 Check for empty array [] 04 Check for negative values [-20, -10, -5, -1] [-20, -1]

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

68 Chapter 4. Arrays

Page 75: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0654 : Array - Find the median of the array

Description

Write a function find_median_array(int arr) which calcualates the median of the elements of the array andreturns the calculated value. Return 0 if the array is empty.

Samples

Number Explanation Input Output1 Check for a general case. [10, 20, 1, 2, 4] 12 Check when zero as an input number [10, 20, 2, 1, 0, 4] 1.53 Check for empty array [] 04 Check for negative values [-2, -4, -2, -7] -3

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

4.3. asg_a0654 : Array - Find the median of the array 69

Page 76: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0655 : Array - Find element occuring maximum number oftimes.

Description

Write a function find_occured_max(int arr) to find the element which has occurred for the maximum num-ber of times in an array. Return 0 if the array is empty. Return 1 if all the numbers have appeared equal times.

Samples

Number Explanation Input Output1 Check for a general case. [1, 2, 2, 4] 22 Check when zero as an input number [1, 2, 0, 4] 13 Check for empty array [] 0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

70 Chapter 4. Arrays

Page 77: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0656 : Array - Fill an array with the multiples of 3, then removethe numbers which are divisible by 5. Fill the empty spaces sogenerated with -1

Description

Write a function fill_array(int n) which fills the array of n length with multiples of 3. Then remove thoseelements which are divisible by 5. This would leave you with few empty spaces in the array. Fill these empty spaceswith -1. Return the finaly generated array.

Samples

Number Explanation Input Output1 Check for a general case. [5] [3, 6, 9, 12, -1]2 Check when zero as an input number [10] [3, 6, 9, 12, -1, 18, 21, 24, 27, -1]3 Check for empty array [0] 0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

4.5. asg_a0656 : Array - Fill an array with the multiples of 3, then remove the numbers which aredivisible by 5. Fill the empty spaces so generated with -1

71

Page 78: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0657 : Array - Find an array with random elements

Description

Write a function fill_random(int n) to fill an array of length n with randomly generated elements. Return thenewly generated array.

Samples

Number Explanation Input Output1 Check for a general case. [3] [2, 10, 23]

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

72 Chapter 4. Arrays

Page 79: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0803 : Array - Find the Prime numbers using Sieve of Eratos-thenes.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0890 : Array - Find out 1500th ugly number

Description

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...shows the first 11 ugly numbers. By convention, 1 is included. Write a function find_ugly(int nth) to findand print the 1500th ugly number. The function takes input the nth place which is to be found for ugly number. Herenth = 1500

4.7. asg_a0803 : Array - Find the Prime numbers using Sieve of Eratosthenes. 73

Page 80: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a2207 : Array - Perform sum and multiplication of multiple ele-ments in a array/list/vector.

Description

Define a function mysum() and a function mymultiply() that sums and multiplies (respectively) all the numbers in alist/array of numbers. For example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) should return 24.

74 Chapter 4. Arrays

Page 81: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Num-ber

Explanation Input Output

1 Sum works correctly. [1, 2, 3, 4] 102 Sum works correctly for negative numbers. [1, -1, 2, -2, 4] 43 Multiplication works correctly. [1, 2, 3, 4, 5] 1204 Multiplication works correctly for negative

numbers.[1, -2, 3, 4] -24

5 Multiplication works correctly for largenumbers.

[1000000, 2000000,9000000]

18000000000000000000

Function

Function Signature

int mysum((list of integers) int_list)

Function Arguments

Number Type Name Explanation Remarks1 list of integers int_list List of integers to be worked upon.

Return Value

Number Type Name Explanation Remarks1 int NA Sum of the elements of a list.

Function Placeholder

int mysum((list of integers) int_list) {

// Write the function body here.

}

asg_a2245 : Array - Sum of multiples of 3 or 5 below 1000

Description

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiplesis 23. Write a function sum_all_multiples() which returns the sum of all the multiples of 3 and 5 below 1000.

Samples

Number Explanation Input Output1 Check if function is correct 23331668

4.10. asg_a2245 : Array - Sum of multiples of 3 or 5 below 1000 75

Page 82: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int sum_all_multiples()

Function Arguments

Number Type Name Explanation Remarks1 No Arguments None The function takes no arguements.

Return Value

Number Type Name Explanation Remarks1 int NA The calculted return value.

Function Placeholder

int sum_all_multiples() {

// Write the function body here.

}

asg_a2422 : Array - Find element occuring minimum times

Description

Write a function find_occured_min(int arr) to find the element which has occurred for the minimum num-ber of times in an array. Return 0 if the array is empty. Return 1 if all the numbers have appeared equal times.

Samples

Number Explanation Input Output1 Check for a general case. [1, 2, 2, 4, 4] 12 Check when zero as an input number [1, 2, 0, 4] 13 Check for empty array [] 0

Function

Function Signature

void alter_case_1(char *str)

76 Chapter 4. Arrays

Page 83: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a2210 : Array - Check for value in given array.

Description

Write a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and returnsTrue if x is a member of a, False otherwise. (Note that this is exactly what the in operator does, but for the sake of theexercise you should pretend Python did not have this operator.)

Samples

Number Explanation Input Output1 Check if function is correst [2, [1, 2, 3, 4]] True

Function

Function Signature

boolean is_member([ANY] value, [list of ANY] mylist)

Function Arguments

Number Type Name Explanation Remarks1 list of ANY mylist List of elements. The list can have data of multiple types.

Return Value

Number Type Name Explanation Remarks1 boolean NA True or False depending on the result.

4.12. asg_a2210 : Array - Check for value in given array. 77

Page 84: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

boolean is_member([ANY] value, [list of ANY] mylist) {

// Write the function body here.

}

asg_a0923 : String - Convert a decimal to hexadecimal.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

78 Chapter 4. Arrays

Page 85: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0927 : String - Convert a hexadecimal to decimal.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0928 : String - Convert a hexadecimal to octal.

Description

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

4.14. asg_a0927 : String - Convert a hexadecimal to decimal. 79

Page 86: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0929 : String - Convert a decimal to binary.

Description

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

80 Chapter 4. Arrays

Page 87: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0930 : String - Convert a binary to decimal.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

4.17. asg_a0930 : String - Convert a binary to decimal. 81

Page 88: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

}

asg_a0931 : String - Convert a hexadecimal to binary.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

82 Chapter 4. Arrays

Page 89: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0932 : String - Convert a binary to hexadecimal.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0933 : String - Convert a binary to octal.

Description

Write a function alter_case_1("Hello World") which converts the case of the characters. The first charactershould be capital. Special charcters are counted as a character but no operation is performed on them.

4.19. asg_a0932 : String - Convert a binary to hexadecimal. 83

Page 90: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0934 : String - Convert a octal to binary.

Description

Write a function convert_octal_to_binary().

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

84 Chapter 4. Arrays

Page 91: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

4.21. asg_a0934 : String - Convert a octal to binary. 85

Page 92: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

86 Chapter 4. Arrays

Page 93: Release 1.0 Rishi Agrawal

CHAPTER 5

Strings

asg_a0001 : String - Change the case of a sentance.

Description

Write a function alter_case_1("Hello World") which converts the case of the characters. The first charactershould be capital. Special charcters are counted as a character but no operation is performed on them.

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon.

87

Page 94: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0003 : String - Program to have alternate case in a string, like“hElLoWoRlD”

Description

Write a function alter_case_2("Hello World") which converts the case of the characters. The first charactershould be small.’

Notes

Note 1

This is a general note.

Samples

Number Explanation Input Output1 See if the function works correctly. HelloWorld hELLOwORLD2 See if it works correctly on all lowercase characters. helloworld hELLOWORLD3 See if it works correctly on all Uppercase chars HELLOWORLD helloworld4 See if it works correctly on blank strings.5 See if it works correctly on special characters. Hello!Wo#rl% 5 4d hELLO!wO#RL% 5 4D

Function

Function Signature

void alter_case_2(char *input, char *retval)

88 Chapter 5. Strings

Page 95: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_2(char *input, char *retval) {

// Write the function body here.

}

asg_a0004 : String - Find the lowercase characters in a string.

Description

Write a function find_lowercase("HelloWorld") which returns a string with lowercase characters present inthe string.

Notes

Note 1

This is a general note.

Samples

Number Explanation Input Output1 Check if the function works Hello World elloorld2 Check if it works if all the characters are capital HELLOWORLD3 Check if it works for all the characters small helloworld helloworld4 Check if special chars are removed Hell o ! @#$% world elloworld

Function

Function Signature

void find_lowercase(char *input, char *retval)

5.3. asg_a0004 : String - Find the lowercase characters in a string. 89

Page 96: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upon.2 C String retval String with the lowercase characters.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void find_lowercase(char *input, char *retval) {

// Write the function body here.

}

asg_a0007 : String - Find the upper case characters in a string.

Description

Write a function find_uppercase("Hello") which returns a string with all the upper case characters in thestring passed.

Notes

Note 1

This is sample note

Samples

Num-ber

Explanation Input Output

1 Check if the function works. Hello H2 Check if the function works if string has all the upper case

charaters.HELLOWORLD

HEL-LOWORLD

3 Check if the function works if string has all the lower casecharacters

hello world

4 Check if the function works if string has some specialcharacters.

Hello !@#$World

HW

90 Chapter 5. Strings

Page 97: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case(char *input, char *retval)

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String retval String with the case converted.

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case(char *input, char *retval) {

// Write the function body here.

}

asg_a0013 : String - Toggle the case of all the charcters in a string.

Description

Write a function toggle_case() which takes input a string and toggles the case of all the characters in the string.

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output1 Check for basic functionality. HelloWorld hELLOwORLD2 Check for functionality with spaces. Hello World hELLO wORLD3 Check for functionality with special characters. Hello @#$ World hELLO @#$ wORLD4 Check for functionality with blank string.5 Check for functionality with alphanumeric string. He12Wo hE12wO

5.5. asg_a0013 : String - Toggle the case of all the charcters in a string. 91

Page 98: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

char * toggle_case(str string)

Function Arguments

Number Type Name Explanation Remarks1 char * string The string whose case has to be toggled.

Return Value

Number Type Name Explanation Remarks1 char * NA The string with the case toggled.

Function Placeholder

char * toggle_case(str string) {

// Write the function body here.

}

asg_a0016 : String - Function to check if character is a consonant

Description

Write a function is_consonant() that takes a character (string of length 1) and checks if the character is a conso-nant or not.

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output1 Check if function is working. A False2 Check if function is working. B True3 Check if function is working for numeric. 2 False4 Check if function is working for special symbols. # False5 Check if function is working for blank input. False

92 Chapter 5. Strings

Page 99: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

int is_consonant(char character)

Function Arguments

Number Type Name Explanation Remarks1 char character The input character.

Return Value

Number Type Name Explanation Remarks1 int NA 0 if the character is consonant else return a Non-Zero value.

Function Placeholder

int is_consonant(char character) {

// Write the function body here.

}

asg_a0154 : String - Design a algorithm to rotate a string.

Description

Write a function rotate_string_left() which takes input the number of characters to rotate and rotates thepassed string.

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output1 [”Hello World”, 3] lo WorldHel

5.7. asg_a0154 : String - Design a algorithm to rotate a string. 93

Page 100: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

char *rotate_string_left (char * string, int n)

Function Arguments

Number Type Name Explanation Remarks1 char * string The string to be worked upon.2 int n The number of characters you should rotate the string.

Return Value

Number Type Name Explanation Remarks1 char * NA The rotated string.

Function Placeholder

char *rotate_string_left (char * string, int n) {

// Write the function body here.

}

asg_a0669 : String - write a function to convert the epoch to date.

Description

Write a function convert_epoch_to_date(

Samples

Number Explanation Input Output1 Check if the function is proper [3] 52 Check if the function is proper [12] 0

Function

Function Signature

int my_floor(float number)

94 Chapter 5. Strings

Page 101: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks3 int number Number whose floow has to be found.

Return Value

Number Type Name Explanation Remarks1 int NA Number which is the floor of the passed float.

Function Placeholder

int my_floor(float number) {

// Write the function body here.

}

asg_a0753 : String - Insert the word “Hello” in the middle. of thewords in an sentence.

Description

Write a function insert_hello(str sentence) which inserts the word Hello in between of each wordpresent in the passed Sentence. (Eg. How are You? to How Hello are Hello You hello?)

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output

Function

Function Signature

char * insert_hello(char * sentence)

5.9. asg_a0753 : String - Insert the word “Hello” in the middle. of the words in an sentence. 95

Page 102: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * sentence The input sentence.

Return Value

Number Type Name Explanation Remarks1 char * NA The resulting String is.

Function Placeholder

char * insert_hello(char * sentence) {

// Write the function body here.

}

asg_a0873 : String - Write a function to remove all the spaces from astring.

Description

Write a function trim_string(String str) to remove all the spaces from a string. All spaces include leadingspaces, trailing spaces and the spaces in between the words.

Notes

Note 1

Do not use the inbuilt functions in the language.

Samples

Number Explanation Input Output1 Check if it works in the simple case. Hello World! How are you. HelloWordl!Howareyou

Function

Function Signature

char * toggle_case(char *string)

96 Chapter 5. Strings

Page 103: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * string The string whose spaces has to be removed.

Return Value

Number Type Name Explanation Remarks1 char * NA The string with the spaces removed..

Function Placeholder

char * toggle_case(char *string) {

// Write the function body here.

}

asg_a0935 : String - Add two Hex Strings.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

5.11. asg_a0935 : String - Add two Hex Strings. 97

Page 104: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a0936 : String - Add two Octal Strings.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

98 Chapter 5. Strings

Page 105: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a0937 : String - Add two binary numbers which are stored asstrings.

Description

Samples

Number Explanation Input Output1 Check for a general case. HelloWorld HeLlOwOrLd2 Check for all “lowercase” characters. helloworld HeLlOwOrLd3 Check for all “UPPERCASE” characters. HELLOWORLD HeLlOwOrLd

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a2204 : String - Find the length of a string.

Description

Define a function mylen() that computes the length of a given of string. Do not use strlen() function.

5.13. asg_a0937 : String - Add two binary numbers which are stored as strings. 99

Page 106: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Notes

Note 1

Do not use strlen() function.

Samples

Number Explanation Input Output1 Check for a string hello world 112 Check for a blank string 0

Function

Function Signature

int mylen(char *string)

Function Arguments

Number Type Name Explanation Remarks1 char * string Pointer to the string.

Return Value

Number Type Name Explanation Remarks1 int NA Length of the string.

Function Placeholder

int mylen(char *string) {

// Write the function body here.

}

asg_a2205 : String - Check character for vowel

Description

Write a function is_vowel(char c) a string (of length 1) and returns True if it is a vowel, False otherwise.

100 Chapter 5. Strings

Page 107: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Notes

Note 1

The function should not work for strings with lengths greater than 1.

Samples

Number Explanation Input Output1 Check for a vowel a True2 Check for a vowel e True3 Check for a vowel i True4 Check for a upper case vowel A True5 Check for a vowel o True

Function

Function Signature

int is_vowel(char *string)

Function Arguments

Number Type Name Explanation Remarks1 char * string String to be worked upon.

Return Value

Num-ber

Type Name Explanation Re-marks

1 int NA 0 if the string if of single character and that character is a vowel else returnnon-zero

Function Placeholder

int is_vowel(char *string) {

// Write the function body here.

}

asg_a2208 : String - Reverse a string.

Description

Write a function myreverse() which will reverse a string passed to it. Do not use the strlen() function.

5.16. asg_a2208 : String - Reverse a string. 101

Page 108: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Notes

Note 1

Do not use the strlen() function.

Samples

Number Explanation Input Output1 Reverse a string with odd number of characters. radar radar2 Reverse a string with even number of characters. hello, world! !dlrow ,olleh3 Reverse a blank string.

Function

Function Signature

char * myreverse(char *string)

Function Arguments

Number Type Name Explanation Remarks1 char * string String to be reversed.

Return Value

Number Type Name Explanation Remarks1 char * NA Return the address of the passed string with reversed characters.

Function Placeholder

char * myreverse(char *string) {

// Write the function body here.

}

asg_a2209 : String - Check a string for palindrome.

Description

Define a function is_palindrome() that recognizes palindromes (i.e. words that look the same written back-wards). For example, is_palindrome("radar") should return Success. In case of blank strings it shouldreturn Success

102 Chapter 5. Strings

Page 109: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Notes

Note 1

Do not use inbuilt functions for string reversal and comparisons.

Samples

Number Explanation Input Output1 Check for a palindrome string odd numbered “radar” True2 Check for a non-palindrome string. Hello World False3 Check for a blank string. False4 Check for a even length string. HEYYEH True

Function

Function Signature

int is_palindrome(char *string)

Function Arguments

Number Type Name Explanation Remarks1 char * string The string to be tested for palindrome.

Return Value

Number Type Name Explanation Remarks1 int NA Zero if the string is a palindrome, 1 other wise.

Function Placeholder

int is_palindrome(char *string) {

// Write the function body here.

}

asg_a2212 : String - Generate n times a character

Description

Define a function generate_n_chars() that takes an integer n and a character c and returns a string, n characterslong, consisting only of c:s. For example, generate_n_chars(5, “x”) should return the string “xxxxx”.

5.18. asg_a2212 : String - Generate n times a character 103

Page 110: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Samples

Number Explanation Input Output1 Check for a general case. [5, ‘a’] aaaaa

Function

Function Signature

int mymax(int n, char c, char *string)

Function Arguments

Number Type Name Explanation Remarks1 int n Number of times character should be repeated.2 char c The character to be repeated.

Return Value

Number Type Name Explanation Remarks1 int NA Was the function successful

Function Placeholder

int mymax(int n, char c, char *string) {

// Write the function body here.

}

asg_a2218 : String - Check palindrome phrases

Description

Write a function check_phrase_palindrome() of a palindrome recognizer that also accepts phrase palin-dromes such as “Go hang a salami Im a lasagna hog.”, “Was it a rat I saw?”, “Step on no pets”, “Sit on a potatopan, Otis”, “Lisa Bonet ate no basil”, “Satan, oscillate my metallic sonatas”, “I roamed under it as a tired nude Maori”,“Rise to vote sir”, or the exclamation “Dammit, Im mad!”. Note that punctuation, capitalization, and spacing are beingignored.

Samples

Number Explanation Input Output1 Rise to vote Sir True

104 Chapter 5. Strings

Page 111: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function

Function Signature

void alter_case_1(char *str)

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a2219 : String - Check pangram

Description

Write a function check_pangram(). A pangram is a sentence that contains all the letters of the English alphabet atleast once, for exmaple: The quick brown fox jumps over the lazy dog. Your task here is to write a function to checka sentence for pangram or not.

Samples

Number Explanation Input Output1 The quick brown fox jumps over the 14 lazy dog True

Function

Function Signature

void alter_case_1(char *str)

5.20. asg_a2219 : String - Check pangram 105

Page 112: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Arguments

Number Type Name Explanation Remarks1 char * str String to be worked upon

Return Value

Number Type Name Explanation Remarks1 void NA Nothing to be returned.

Function Placeholder

void alter_case_1(char *str) {

// Write the function body here.

}

asg_a2223 : String DISPUTE - Caesar Cipher

Description

In cryptography, a Caesar cipher is a very simple encryption techniques in which each letter in the plain text is replacedby a letter some fixed number of positions down the alphabet. For example, with a shift of 3, A would be replacedby D, B would become E, and so on. The method is named after Julius Caesar, who used it to communicate with hisgenerals. ROT-13 (“rotate by 13 places”) is a widely used example of a Caesar cipher where the shift is 13. Write afunction myceaser_encode() which takes a string and the number of shift and encode the string. Note that thespecial characters SHOULD not be shifted. In another assignment Write another function myceaser_decode()which takes an encrypted message and the shift number and decrypts the string.

Samples

Number Explanation Input Output1 Check if function is proper Tnevzn Garima

Function

Function Signature

char * myceaser_encode(char * string, int shift)

Function Arguments

Number Type Name Explanation Remarks1 str string The string to be encrypted.2 int shift The number of characters to be shifted to encrypt the message.

106 Chapter 5. Strings

Page 113: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Return Value

Number Type Name Explanation Remarks1 str NA The encrypted string.

Function Placeholder

char * myceaser_encode(char * string, int shift) {

// Write the function body here.

}

asg_a2236 : String - Print the frequency of characters in a file.

Description

Write a function char_freq_table() that takes a file name and returns a list of characters the file has along withthe count.

Samples

Num-ber

Explanation Input Output

1 Check iffunction isproper

/home/garima/pinnacle/leaders-pinnacle/tool/data/assignments/data_files/asg_a2236_freq.txt

[{‘H’: 1, ‘E’: 1, ‘!’: 1,‘L’: 2, ‘O’: 1}]

Function

Function Signature

char * toggle_case(str string)

Function Arguments

Number Type Name Explanation Remarks1 char * string The string whose case has to be toggled.

Return Value

Number Type Name Explanation Remarks1 char * NA The string with the case toggled.

5.22. asg_a2236 : String - Print the frequency of characters in a file. 107

Page 114: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

Function Placeholder

char * toggle_case(str string) {

// Write the function body here.

}

asg_a2238 : String - Find words with occurences as 1

Description

Write a function extract_single_occurences that given the file name of a text will return all the words whichoccur only one time. Make sure your program ignores capitalization.

Samples

Num-ber

Explanation Input Output

1 Check if functionis proper

/home/garima/pinnacle/leaders-pinnacle/tool/data/assignments/data_files/asg_a2238_hapax.txt

[’is’, ‘matter’,‘hell’]

Function

Function Signature

int mymax(int num1, int num2)

Function Arguments

Number Type Name Explanation Remarks1 int num1 The first number.2 int num2 The second number.

Return Value

Number Type Name Explanation Remarks1 int NA The larger number.

Function Placeholder

int mymax(int num1, int num2) {

// Write the function body here.

}

108 Chapter 5. Strings

Page 115: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

asg_a2254 : String - Change the case of a sentance.

Description

Write a function alter_case_1("Hello World") which converts the case of the characters. The first charactershould be capital. Special charecters are skipped and the next alphabet should be changed according to the previouscharacter.’

Samples

Num-ber

Explanation Input Output

1 See if the function works correctly. HelloWorld HeLlOwOrLd2 See if it works correctly on all “lowercase” characters. helloworld HeLlOwOrLd3 See if it works correctly on all “UPPERCASE”

characters.HELLOWORLD HeLlOwOrLd

4 See if it works correctly on special characters. Hello!Wo#rl% 54d

HeLlO!Wo#Rl% 54D

Function

Function Signature

alter_case(char *input, int )

Function Arguments

Number Type Name Explanation Remarks1 C String input String to be worked upn2 C String input String to be worked upn3 C String input String to be worked upn

Return Value

Number Type Name Explanation Remarks1 string object NA String with the case converted

Function Placeholder

alter_case(char *input, int ) {

// Write the function body here.

}

5.24. asg_a2254 : String - Change the case of a sentance. 109

Page 116: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

110 Chapter 5. Strings

Page 117: Release 1.0 Rishi Agrawal

CHAPTER 6

2 D Arrays

111

Page 118: Release 1.0 Rishi Agrawal

Beginning Programming in C Documentation, Release 1.0

112 Chapter 6. 2 D Arrays

Page 119: Release 1.0 Rishi Agrawal

CHAPTER 7

File Handling

113