Вы находитесь на странице: 1из 9

Paolo Labrador BSIT 3-1

Assignment 1

Unconverted Program #1 (C)


Single Dimension Array
#include<stdio.h>
int main()
{
int n[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int i=0; i<10; i++)
printf("n[%d] = %d\n", i, n[i]);
return 0;
}

Converted Program #1 (vb.net)


Module Module1
Sub Main()
Dim n = New Integer(9) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
For i = 0 To 9
Console.WriteLine("n({0}) = {1}", i, n(i))
Next
End Sub
End Module

Unconverted Program #2 (C)


Two Dimension Array
#include<stdio.h>
int main()
{
int n[5][5] =
{
{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 (int i=0; i<5; i++)
{
for (int j = 0; j<5; j++)
printf("%d\t", n[i][j]);
printf("\n");
}
return 0;
}
Converted Program #2 (vb.net)
Module Module1

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

Unconverted Program #3 (C)


Multiple Dimension Array
#include<stdio.h>
int main()
{
int n[3][3][3] =
{
{
{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(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
for(int k=0; k<3; k++)
printf("%d\t", n[i][j][k]);
printf("\n");
}
printf("\n");
}
return 0;
}
Converted Program #3 (vb.net)
Module Module1

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

Unconverted Program #4 (C)


Area of a Triangle
#include<stdio.h>
int main()
{
int h,b;
float area;
printf("Enter the height of the triangle: ");
scanf("%d",&h);
printf("Enter the base of the triangle: ");
scanf("%d",&b);
/* formula for area of the triangle */
area=(h*b)/2;
printf("The area of the triangle is: ");
printf("%f",area);
return(0);
}

Converted Program #4 (vb.net)


Module Module1
Sub Main()
Dim h, b As Integer
Dim area As Double
Console.Write("Enter the height of the triangle: ")
h = Console.ReadLine()
Console.Write("Enter the base of the triangle: ")
b = Console.ReadLine()
'formula for area of the triangle
area = (h * b) / 2
Console.WriteLine("The area of the triangle is: " & area)
End Sub

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);
}

Converted Program #5 (vb.net)


Module Module1

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

Unconverted Program #6 (C)


Ideal Partner Age
#include<stdio.h>
int main()
{
int age, youngest, oldest;
printf("Enter your age: ");
scanf("%d", &age);
youngest = (age / 2) + 7;
oldest = (age - 7) * 2;
printf("Your ideal partner age is: \n%d up to %d years old", youngest,
oldest);
return 0;
}
Converted Program #6 (vb.net)
Module Module1

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

Unconverted Program #7 (C)


Balloon Sort
#import<stdio.h>
int main()
{
int num, N[10], x, y, z,temp;

printf("How many number would you like to sort: ");


scanf("%d",&num);
printf("Input %d numbers \n",num);

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

Unconverted Program #8 (C)


Odd and Even Checker
#import<stdio.h>
int main()
{
int number;
printf("Enter number: ");
scanf("%d", &number);
if((number%2)==1)
printf("The number is odd.");
else
printf("The number is even.");
return 0;
}
Converted Program #8 (vb.net)
Module Module1

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

Unconverted Program #9 (C)


Pattern Printing
#import<stdio.h>
int main()
{
for (int x=1; x<=3; x++)
{
for (int y=1; y<=x; y++)
printf("%d", x);
printf("\n");
}
}

Converted Program #9 (vb.net)


Module Module1

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

Вам также может понравиться