Project Computer Programming 2
Project Computer Programming 2
Project Computer Programming 2
ARIRAO
Computer Programming 2
BSIT-1B
1. Write a program that’s asks for a dimension of a 2-D array. The user enters the elements
then the program prints the matrix.
using System;
class program
int i,j;
int[,] arr1 = new int[4,3];
for(I=0;I<4;I++)
for(j=0;j<3;j++)
{
arr1[i,j] = Convert.ToInt32(Console.ReadLine());
for(i=0;i<4;i++)
Console.Write("\n");
for(j=0;j<3;j++)
Console.Write("{0}\t",arr1[i,j]);
Console.Write("\n\n");
Console.ReadKey();
2. Write a program to read the values in an array and display it in reverse order.
using System;
class Program
int i,n;
Console.Write("\n");
n = Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
a[i] = Convert.ToInt32(Console.ReadLine());
Console.Write("{0} ",a[i]);
for(i=n-1;i>=0;i--)
Console.Write("{0} ",a[i]);
Console.Write("\n\n");
3. Write a program to print all unique elements in an array. (Unique- means no duplicate).
int n,ctr=0;
int i, j, k;
Console.Write("\n");
n = Convert.ToInt32(Console.ReadLine());
Console.Write("Input {0} elements in the array :\n",n);
for(i=0;i<n;i++)
arr1[i] = Convert.ToInt32(Console.ReadLine());
ctr=0;
if(arr1[i]==arr1[j])
ctr++;
if(arr1[i]==arr1[k])
ctr++;
if(arr1[i]==arr1[i+1])
{
i++;
if(ctr==0)
Console.Write("{0} ",arr1[i]);
Console.Write("\n\n");
}
4. Write a program to merge two arrays of same size sorted in descending order.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication24
{
class Program
{
s1 = Convert.ToInt32(Console.ReadLine());
arr1[i] = Convert.ToInt32(Console.ReadLine());
s2 = Convert.ToInt32(Console.ReadLine());
arr2[i] = Convert.ToInt32(Console.ReadLine());
s3 = s1 + s2;
arr3[i] = arr1[i];
{
arr3[i] = arr2[j];
i++;
j = arr3[k + 1];
arr3[k + 1] = arr3[k];
arr3[k] = j;
Console.Write("\n\n");
Console.ReadKey();
}
}
using System;
int n, i, j, ctr;
n = Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
arr1[i] = Convert.ToInt32(Console.ReadLine());
fr1[i] = -1;
ctr = 1;
if(arr1[i]==arr1[j])
ctr++;
fr1[j] = 0;
if(fr1[i]!=0)
fr1[i] = ctr;
if(fr1[i]!=0)
using System;
namespace HelloWorld
class Program
int i,j=0,k=0,n;
n = Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
Console.Write("El");