0% found this document useful (0 votes)
75 views4 pages

Task No # 01:: Lab 11 Computer Programming Methods

The document contains 4 tasks to write C# methods that: 1. Calculate the square and cube of a user-input number. 2. Generate a multiplication table between user-input start and end points. 3. Check if odd positions in a character array contain vowels. 4. Take an array as input and print its reverse by calling a second method.

Uploaded by

Malik Qudoos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views4 pages

Task No # 01:: Lab 11 Computer Programming Methods

The document contains 4 tasks to write C# methods that: 1. Calculate the square and cube of a user-input number. 2. Generate a multiplication table between user-input start and end points. 3. Check if odd positions in a character array contain vowels. 4. Take an array as input and print its reverse by calling a second method.

Uploaded by

Malik Qudoos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 11 Computer Programming

Methods
TASK NO # 01:
Write a method named square_cube() that computes the square and cube of the value passed
to it and display the result. Ask the user to provide the integer input in the main() and then
call the function.

CODE:
{
static void square_cube(int num)
{
Console.WriteLine("Square of {0} = {1}", num,num*num);
Console.WriteLine("Cube of {0} = {1}", num, num * num *num);
}
static void Main(string[] args)
{
Console.WriteLine("Enter Number");
int n = int.Parse(Console.ReadLine());
square_cube(n);
}
}
OUTPUT:

ABDUL QUDOOS ENROLLMENT NO# 02-131182-


086
Lab 11 Computer Programming
Methods
TASK NO # 02:
Write a method table() which generates multiplicative table of an integer. The function
receives three integers as its arguments. The first argument determine the table to be
generated while the second and the third integer tell the starting and ending point
respectively. Ask the user to provide the three integer as input in the main().

CODE:
{
static void table(int num1, int num2 ,int num3)
{
for(;num2 <=num3 ; num2++)
Console.WriteLine("{0} x {1} = {2}", num1,num2,num1*num2);

}
static void Main(string[] args)
{
Console.Write("Enter Number of which you want to generate the table: ");
int num1 = int.Parse(Console.ReadLine());
Console.Write("Enter start point of table: ");
int num2 = int.Parse(Console.ReadLine());
Console.Write("Enter end point of table: ");
int num3 = int.Parse(Console.ReadLine());
table(num1, num2, num3);

}
}
OUTPUT:

ABDUL QUDOOS ENROLLMENT NO# 02-131182-


086
Lab 11 Computer Programming
Methods
TASK NO # 03:
Write a C# program that inputs a character array and check if the odd positions in an array
contains vowels or not? Make two methods one for array input second for vowel checking.
CODE:
{static void vowel_Checking(char[] array)
{
int odd = 0;
for (int i = 1 ; i < 10; i=i+2)
{
if (array[i] == 'a' || array[i] == 'e' || array[i] == 'i' || array[i] == 'o' || array[i] == 'u')
odd++;
}
if (odd == 0)
Console.WriteLine("Odd position of array does not contains vowel");
else
Console.WriteLine("odd position of an array contain vowel");

}
static void Main(string[] args)
{
char [] array = new char [10];
Console.WriteLine("Enter 10 character");
for (int i = 0; i <10 ; i ++)
array [i] = char.Parse(Console.ReadLine());
vowel_Checking(array);
}
}
OUTPUT:
:

ABDUL QUDOOS ENROLLMENT NO# 02-131182-


086
Lab 11 Computer Programming
Methods
Task #4: Take input of an array in on method and print reverse of that array using
second method.
CODE:
static void reverse_array(int[] array)
{
Console.WriteLine("Reverse array is as follow");
int n = array.Length - 1;
for (int k =n ; k >=0; k --)
Console.Write(array[k] + " ");
}
static void Main(string[] args)
{
Console.WriteLine("Enter value of N");
int n = int.Parse(Console.ReadLine());
int [] array = new int [n];
Console.WriteLine("Enter values in array");
for (int i = 0; i <n ; i ++)
{
Console.Write("array[{0}] = ", i);
array [i] = char.Parse(Console.ReadLine());
}
reverse_array(array);
}
OUTPUT:

ABDUL QUDOOS ENROLLMENT NO# 02-131182-


086

You might also like