Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


Problemas de string e cábulas, Notas de estudo de Matemática

cab matematica: tudo o que você tem que saber

Tipologia: Notas de estudo

2012

Compartilhado em 14/10/2012

nelson-andrade-9
nelson-andrade-9 🇧🇷

1 documento

1 / 4

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
'Problema 1 a) --> obter a soma dos algarismos da string
Dim str As String 'string de entrada,
lida da TextBox1.Text
Dim acc As Integer str =
TextBox1.Text
If str = "" Then Exit Sub ' para o
caso da string estar vazia
If IsNumeric(str) = True Then ' para
confirmar que str é numérica
For Each a As Char In str acc =
acc + AscW(a) - 48
'acc = acc +
Convert.ToInt16(a) - 48
'acc = acc +
Convert.ToUInt16(Convert.ToString(a))
Next
TextBox2.Text = " Soma dos
algarismos = " & acc
End If
End Sub
'Problema 1 b) --> obter os "noves fora" da string numérica
lida
Dim str As String 'string de entrada,
lida da TextBox1.Text
Dim acc As Integer = 0
Dim toto As Boolean = False
str = TextBox1.Text
If IsNumeric(str) = True Then ' para
confirmar que str é numérica
While toto = False
For Each a As Char In str
acc = acc + AscW(a) - 48
Next If acc > 9 Then
str = Convert.ToString(acc)
acc = 0
toto = False Else
toto = True If acc = 9 Then
acc = 0
End If End While
TextBox2.Text = " noves fora : "
& acc Else
TextBox2.Text = " Só aceita
strings numéricas...!"
End If ' se string não numérica
'Probl 2-a) : Serie 1 =
Dim i, N, x, acc As Double
N = InputBox("Input valor de N :")
ListBox1.Items.Clear()
For i = 1 To N
x = 1 / I acc = acc + x
ListBox1.Items.Add("F1(" & i &
")= " & acc & " x= " & x)
Next End Sub
'Problema 2-b) : .Serie 2 =
Dim i, N, x, acc As Double
N = InputBox("Input valor de N :")
ListBox1.Items.Clear()
For i = 1 To N
x = Math.Pow(i, 1 / i)
acc = acc + x
ListBox1.Items.Add("F2(" & i &
")= " & acc & " x= " & x)
Next
End Sub
'Probl 2-c) : Serie 3= 1+
Dim i, N, x, acc, cte As Double
N = InputBox("Input valor de N :")
cte = InputBox("Input valor de cte
(expoente):")
ListBox1.Items.Clear()
For i = 1 To N
x = 1 / Math.Pow(i, cte)
acc = acc + x
ListBox1.Items.Add("F3(" & i &
")= " & acc & " x= " & x)
Next
End Sub
'Problema 2-d) : Serie 4=
Dim i, N, x As Double
N = InputBox("Input valor de N :")
ListBox1.Items.Clear()
For i = 0 To N
x = 0.5 * ((1 / (2 * i + 1)) - (1 / (2
* i + 2)))
ListBox1.Items.Add("F4(" & i &
")= " & x)
Next
End Sub
Faça um programa que leia uma string
ao teclado e
a transfira, caractere por caractere
para um array
Dim i, N, x, acc As Double
Dim toto As Integer
N = InputBox("Input valor de N :")
ListBox1.Items.Clear()
toto = -1
For i = 1 To N
pf3
pf4

Pré-visualização parcial do texto

Baixe Problemas de string e cábulas e outras Notas de estudo em PDF para Matemática, somente na Docsity!

'Problema 1 a) --> obter a soma dos algarismos da string Dim str As String 'string de entrada, lida da TextBox1.Text Dim acc As Integer str = TextBox1.Text If str = "" Then Exit Sub ' para o caso da string estar vazia If IsNumeric(str) = True Then ' para confirmar que str é numérica For Each a As Char In str acc = acc + AscW(a) - 48 'acc = acc + Convert.ToInt16(a) - 48 'acc = acc + Convert.ToUInt16(Convert.ToString(a)) Next TextBox2.Text = " Soma dos algarismos = " & acc End If End Sub 'Problema 1 b) --> obter os "noves fora" da string numéricalida Dim str As String 'string de entrada, lida da TextBox1.Text Dim acc As Integer = 0 Dim toto As Boolean = False str = TextBox1.Text If IsNumeric(str) = True Then ' para confirmar que str é numérica

While toto = False For Each a As Char In str acc = acc + AscW(a) - 48 Next If acc > 9 Then str = Convert.ToString(acc) acc = 0 toto = False Else toto = True If acc = 9 Then acc = 0 End If End While TextBox2.Text = " noves fora : " & acc Else TextBox2.Text = " Só aceita strings numéricas...!" 'Probl 2-a) : Serie 1 = End If ' se string não numérica Dim i, N, x, acc As Double N = InputBox("Input valor de N :") ListBox1.Items.Clear() For i = 1 To N x = 1 / I acc = acc + x ListBox1.Items.Add("F1(" & i & ")= " & acc & " x= " & x) Next End Sub 'Problema 2-b) : .Serie 2 = Dim i, N, x, acc As Double N = InputBox("Input valor de N :")

ListBox1.Items.Clear() For i = 1 To N x = Math.Pow(i, 1 / i) acc = acc + x ListBox1.Items.Add("F2(" & i & ")= " & acc & " x= " & x) Next End Sub 'Probl 2-c) : Serie 3= 1+ Dim i, N, x, acc, cte As Double N = InputBox("Input valor de N :") cte = InputBox("Input valor de cte (expoente):") ListBox1.Items.Clear() For i = 1 To N x = 1 / Math.Pow(i, cte) acc = acc + x ListBox1.Items.Add("F3(" & i & ")= " & acc & " x= " & x) Next End Sub 'Problema 2-d) : Serie 4= Dim i, N, x As Double N = InputBox("Input valor de N :") ListBox1.Items.Clear()

For i = 0 To N x = 0.5 * ((1 / (2 * i + 1)) - (1 / (

  • i + 2))) ListBox1.Items.Add("F4(" & i & ")= " & x) Next End Sub

Faça um programa que leia uma string ao teclado e a transfira, caractere por caractere para um array Dim i, N, x, acc As Double Dim toto As Integer N = InputBox("Input valor de N :") ListBox1.Items.Clear() toto = - For i = 1 To N

toto = toto * (-1) x = toto / i acc = acc + x ListBox1.Items.Add("F5(" & i & ")= " & acc & " x= " & x) Next End Sub seguidamente transfira-a para uma textbox, na forma de string, com os caracteres em ordem inversa da ordem de entrada. Se assim considerar, pode não recorrer ao array intermediario da aliena a Dim str1, str2 As String Dim N, i As Integer Dim v() As String str1 = TextBox1.Text If str1 = "" Then Exit Sub ReDim v(str1.Length + 1) ListBox1.Items.Clear() For Each a As Char In str v(N) = Convert.ToString(a) N = N + 1 ListBox1.Items.Add("V(" & N - 1 & " ) = " & v(N - 1)) Next For i = 0 To N str2 = str2 & v(N - i) Next TextBox2.Text = str End Sub End Class

'Problema 1 Dim N, i As Integer 'Numero de elementos do array Dim H() As Double ' vector H() que vai conter os elementos Dim media As Double 'a) N = InputBox(" Input valor de N : ") ReDim H(N) ListBox1.Items.Clear() 'Opcional - so para display For i = 0 To N H(i) = 2 * i ListBox1.Items.Add("H(" & i & ")= " & H(i)) 'Opcional - so para display Next ListBox1.Items.Add(" (1) Media H()= " & H.Average) -2ª- é calculando manualmente o valor, usando um outro ciclo For For i = 0 To N media = media + H(i) Next media = media / (N + 1) ListBox1.Items.Add(" (2) Media H()= " & media) End Sub ' PRB2 - Determinar se x, LIDO AO TECLADO É, OU NÃO, MULTIPLO DE 11 Dim x As Integer

x = InputBox(" INPUT x :") If x Mod 11 = 0 Then MsgBox(x & " é multiplo de 11") Else MsgBox(x & " NÃO é multiplo de 11") End If End Sub 'Determinar a intersecção de 2 rectas num espaço 2dimensões Dim a0, a1, b0, b1, k1, k2 As Double Dim det As Double Dim x0, y0 As Double a0 = InputBox(" Input a0 :") : b0 = InputBox(" Input b0 :") a1 = InputBox(" Input a1 :") : b1 = InputBox(" Input b1 :") k1 = InputBox(" Input k1 :") : k2 = InputBox(" Input k2 :") det = a0 * b1 - a1 * b0 'Calulo do determiante da matriz ListBox1.Items.Clear() ListBox1.Items.Add(" Matriz ") ListBox1.Items.Add(a0 & " -- " & b0 & " --> " & k1) ListBox1.Items.Add(a1 & " -- " & b1 & " --> " & k2) ListBox1.Items.Add(" Determinante = " & det)

If det <> 0 Then x0 = (k1 * b1 - k2 * b0) / det y0 = (a0 * k2 - a1 * k1) / det ListBox1.Items.Add(" ----------------------") ListBox1.Items.Add(" x0 = " & x0 & " y0 = " & y0) Else ListBox1.Items.Add(" ----------------------") ListBox1.Items.Add(" Sistema impossível....!") End If End Sub

FctLIKE Dim dist As Integer TextBox3.Text = TextBox1.Text Like TextBox2.Text Dim str As String str = TextBox1.Text TextBox3.Text = str.Length 'estas 2 ultimas linhas de código são equivalentes a: ' TextBox3.Text = TextBox1.Text.Length

Else MsgBox(" A string " & str & "não é numérica") End If End Sub Dim i As Double TextBox1.Visible = False If N <= 0 Then MsgBox(" Valor de N não definido!") ListBox1.Items.Clear() For i = 0 To N - 1 v(i) = Math.Sin(i * Math.PI / 180) * Math.Exp(-i * 0.05) ListBox1.Items.Add(" V(" & i & " )= " & Math.Round(v(i), 7)) Next End Sub Dim i As Double Dim str As String = "1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12, 12,12, 12, 16, 14, 14, 16, 16, 16, 16, 20, 17, 17, 20, 21, 19, 20, 22, 21, 22, 23, 23, 24, 24, 24, 24, 24, 32, 24, 25" TextBox1.Visible = True TextBox1.Text = str If N <= 0 Then MsgBox(" Valor de N não definido!") ListBox1.Items.Clear() For i = 0 To N – 1 If i < 2 Then v(i) = i + 1 Else

v(i) = v(i - v(i - 1)) + v(i - v(i - 2)) End If ListBox1.Items.Add(" V(" & i & " )= " & Math.Round(v(i), 7)) Next End Sub TextBox1.Visible = False End Sub Dim i, acc As Double TextBox1.Visible = False If N <= 0 Then MsgBox(" Valor de N não definido!") ListBox1.Items.Clear() acc = 0 For i = 0 To N - 1 acc = acc + 1 / Fact(i) ListBox1.Items.Add(" V(" & i & " )= " & acc ) Next v(i) = acc ListBox1.Items.Add(" e= " & Math.Round(v(i), 7)) End Sub Dim i, prod As Double prod = 1 For i = 1 To x prod = prod * I Next Return (prod) End Function Dim i, acc As Double

TextBox1.Visible = False If N <= 0 Then MsgBox(" Valor de N não definido!") ListBox1.Items.Clear() acc = 0 For i = 1 To N - 1 acc = acc + 1 / (i ^ 2) ListBox1.Items.Add(" V(" & i & " )= " & Math.Sqrt(acc * 6)) Next v(i) = Math.Sqrt(acc * 6) ListBox1.Items.Add(" Pi= " & Math.Round(v(i), 7)) End Sub Dim i, acc, a As Double TextBox1.Visible = False If N <= 0 Then MsgBox(" Valor de N não definido!" ListBox1.Items.Clear() acc = 0 a = 1 For i = 0 To N - 1 acc = acc + a / (2 * i + 1) a = a

  • (-1) ListBox1.Items.Add(" V(" & i & " )= " & 4 * acc) Next v(i) = acc * 4 ListBox1.Items.Add(" Pi= " & Math.Round(v(i), 7))

End Sub