Skip to content
VUBuddy

CS201P Problem Statement

Introduction to Programming (Practical) PDF 509 KBUpdated 23 Oct 2026
Quiz CS201P Problem Statement PDF 509 KB
vubuddy.com
Type
Quiz
Course
CS201P Introduction to Programming (Practical)
Size
PDF 509 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 509 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 1, 2, 4 of 9. Download the file for all 9 pages.

Lab # 3

Week = 1-May -- 5-May-2023

Functions

Write a program in which you have to define a function displayDiagnol which will have two integer arguments named rows and cols. In the main function, take the values of rows and columns from the users. If the number of rows is same as numbers of columns then call the displayDiagnol function else show a message on screen that number of rows and columns is not same.

The following logic will be implemented inside the displayDiagnol function:

The function will take the value of rows and cols which are passed as argument and print the output in matrix form. To print the values in the matrix form, nested loops should be used. For each loop, you have to use a counter variable as counter. When the value of counters for each loop equals, then it prints the value of row at that location and prints hard coded zero at any other location.

Example if the user enters rows and cols as 3, then the output should be like this

Example: when rows and columns are not same.

Example: when rows and columns are same.

Solution:

void displayDiagonal(int,int); // function declaration

int main(){

int rows, columns;//variable declaration and initialization

rows = 0;

columns = 0;

cout<< " Enter the number of rows:";//Taking number of rows as input

cin>> rows;

cout<< " Enter the number of columns:";//Taking columns of rows as input

cin>> columns;

if(rows == columns)//conditional check for square matrix

displayDiagonal(rows,columns); // call function

else

cout<< " Wrong input! Num of rows should be equal to num of columns"; “Calculate the average age of a class of ten students using while loop. Prompt the user to enter the age of each student.”

  •  We need 10 values of variable age of int type to calculate the average age.

int age;

cin>> age;

  •  Average can be calculated by doing addition of 10 values and dividing sum with 10.

Solution:

main() {

int age=0;

// declaring ageCounter variable to check the number of iterations int ageCounter=0;

All CS201P files →
CS201P Introduction to Programming (Practical) All CS201P handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.