Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

COMSATS Institute of Information Technology Lahore

Assignment 3– Semester FALL 2020


Course Title: Introduction to Computer Programming Course Code: CSC 141
Resource Person: Imran Latif Class: SP20-BPH-BSM
Due Date: 24/12/2020 Total Marks: 15

Q 1. Write a function average which accepts an array and calculate and return the average of the even numbers of
the array to the main function.

Note: prototype of the function should be as follows:

float average (int A[],int s);

Q 2. Write a function that displays the values on the diagonal of its 10 x10 matrix parameter.

Q 3. Given the following declaration:

int examPrep [12][15];

A. Write a loop to print the first row of the array.

B. Write a loop to print the first column of the array.

C. Write a loop to print the first seven rows of the array, each on a single line.

D. Write a loop to print the entire array backward and upside down, so that the last line appears first, with the
last column on the left.

Q 4. Write loops that perform each of the following single-subscripted array operations:

a) Initialize the 10 elements of integer array counts to zeros.


b) Add 1 to each of the 15 elements of integer array bonus.
c) Read the 12 values of floating-point array Mtemp from the keyboard.
d) Print the five values of integer array bestScores in column format.

Q 5. How can we determine the length of an array in C language?

Q 6. Write a C Program to find the Largest & Smallest Elements in an Array.

Page 1 of 2
Q 7. Write a C Program to count vowels, consonants, digits, special characters in a given string.

Q 8. Input a string and print “Only Alphabets” if the string only contains alphabets(A-Z, a-z), “Only numbers” if
the string only contains numerical digits(0-9), “Only Alphanumeric” if the string only contains alphabets and
numerical digits(A-Z, a-z, 0-9) or “Mixture” if there are other characters too. Ignore space character while
computing the result. Assume that the input string will be less than 50 characters long.

Q 9. Write a program that inputs four strings that represent floating-point values, converts the strings to double
values, sum the values and print the total of the four values.

Q 10. Implement the following built-in functions with the help of examples.

isdigit(), isalpha()

strcmp() &strlen()

strcpy() & strncpy()

strchr() & strrchr()

Q 11. Write a program that inputs a line of text and a search character and uses function strchr to determine the
total occurrences of the character in that line. You must input the string from the user.

char string [50]="Pakistanis ares great.sand s dis";

Sample Output:

Q 12. Write a program that will create a database for your class. Create an array of structure to store the records of
the students. Store the records of at least 10 students. Your program should display the single record one at a line.

The attributes of the structure are as follows:

StdName, Reg#, ICPMarks, Age, Gender.

A. Declare appropriate data types for the above attributes.


B. Read the student data from the user in the struct array.

Page 2 of 2

You might also like