Академический Документы
Профессиональный Документы
Культура Документы
Assignment 1
Sub Main()
Dim n = New Integer(4, 4) {{0, 0, 0, 0, 0}, {1, 2, 3, 4, 5}, {2, 4,
6, 8, 10}, {3, 6, 9, 12, 15}, {4, 8, 12, 16, 20}}
For i = 0 To 4
For j = 0 To 4
Console.Write("{0}{1}", n(i, j), vbTab)
Next
Console.WriteLine()
Next
End Sub
End Module
Sub Main()
Dim n = New Integer(2, 2, 2) {{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {{9,
8, 7}, {6, 5, 4}, {3, 2, 1}}, {{4, 4, 4}, {4, 4, 4}, {4, 4, 4}}}
For i = 0 To 2
For j = 0 To 2
For k = 0 To 2
Console.Write("{0}{1}", n(i, j, k), vbTab)
Next
Console.WriteLine()
Next
Console.WriteLine()
Next
End Sub
End Module
End Module
Unconverted Program #5 (C)
Average of Numbers
#include<stdio.h>
void main()
{
int n, count;
float sum = 0, x, avg;
printf("\nEnter How Many Numbers to be Averaged: ");
scanf("%d", &n);
for(count = 1; count <= n; count++)
{
printf("x = ");
scanf("%f", &x);
sum += x;
}
avg = sum / n;
printf("\nThe Average of Numbers is : %0.2f", avg);
}
Sub Main()
Dim n, sum As Integer
Dim avg As Double
Console.Write("Enter How Many Numbers to be Averaged: ")
n = Console.ReadLine()
For i = 1 To n
Console.Write("Enter Number {0}: ", i)
sum = sum + Console.ReadLine()
Next
avg = sum / n
Console.WriteLine("The Average of Numbers is: {0}", avg)
End Sub
End Module
Sub Main()
Dim age, youngest, oldest As Integer
Console.Write("Enter your age: ")
age = Console.ReadLine()
youngest = (age / 2) + 7
oldest = (age - 7) * 2
Console.WriteLine("Your ideal partner age is: ")
Console.WriteLine("{0} uo to {1} years old.", youngest, oldest)
End Sub
End Module
for(x=0;x<num;x++)
scanf("%d",&N[x]);
for(x=0;x<num;x++)
{
for(y=0;y<num-x;y++)
{
if(N[x] > N[x+y])
{
temp=N[x];
N[x] =N[x+y];
N[x+y]=temp;
}
}
printf("step %d : ",x+1);
for(z=0;z<num;z++)
printf("%3d",N[z]);
printf("\n");
}
}
Converted Program #7 (vb.net)
Module Module1
Sub Main()
Dim num, n(9), temp As Integer
Console.Write("How many number would you like to sort: ")
num = Console.ReadLine()
Console.WriteLine("Input {0} number: ", num)
For i = 1 To num
n(i) = Console.ReadLine()
Next
For x = 1 To num
For y = 1 To num - x
If (n(x) > n(x + y)) Then
temp = n(x)
n(x) = n(x + y)
n(x + y) = temp
End If
Next
Console.Write("Step {0}: ", x + 1)
For z = 1 To num
Console.Write("{0}", n(z))
Next
Console.WriteLine()
Next
End Sub
End Module
Sub Main()
Dim number
Console.Write("Enter number: ")
number = Console.ReadLine()
If ((number Mod 2) = 1) Then
Console.WriteLine("The number is odd.")
Else
Console.WriteLine("The number is even.")
End If
End Sub
End Module
Sub Main()
For x = 1 To 3
For y = 1 To x
Console.Write("{0}", x)
Next
Console.WriteLine()
Next
End Sub
End Module
Unconverted Program #10 (C)
Debut Computer
#import<stdio.h>
#import<string.h>
int main()
{
int age, years;
char sex[10];
printf("Enter sex (F/M): ");
gets(sex);
printf("Enter age: ");
scanf("%d", &age);
if(strcmp(sex, "f") == 0 || strcmp(sex, "F") == 0)
{
if(age==18)
printf("Your debut would be, or could be done by now, or
could be right now, this year");
else if (age<18)
{
years = 18 - age;
printf("Your debut will be %d year/s from now.", years);
}
else
printf("Your debut is done for.");
}
else
{
if(age==21)
printf("Your debut would be, or could be done by now, or
could be right now, this year");
else if (age<21)
{
years = 21 - age;
printf("Your debut will be %d year/s from now.", years);
}
else
printf("Your debut is done for.");
}
}
Converted Program #10 (vb.net)
Module Module1
Sub Main()
Dim age, years As Integer
Dim sex As Char
Console.Write("Enter sex (F/M) : ")
sex = Console.ReadLine()
Console.Write("Enter age: ")
age = Console.ReadLine()
If (sex = "f" Or sex = "F") Then
If (age = 18) Then
Console.WriteLine("Your debut would be, or could be done by
now, or could be right now, this year")
ElseIf (age < 18) Then
years = 18 - age
Console.WriteLine("Your debut will be {0} year/s from now.",
years)
Else
Console.WriteLine("Your debut wis done for.")
End If
Else
If (age = 21) Then
Console.WriteLine("Your debut would be, or could be done by
now, or could be right now, this year")
ElseIf (age < 21) Then
years = 21 - age
Console.WriteLine("Your debut will be {0} year/s from now.",
years)
Else
Console.WriteLine("Your debut is done for.")
End If
End If
End Sub
End Module