Assignment
Assignment
#include <stdio.h>
int main(void)
{
int fahr;
int celsius;
printf("Enter a temperature in Fahrenheit: ");
scanf("%d", &fahr);
celsius = (fahr - 32)*3/9;
printf("The temperature in Celsius is %d\n", celsius);
return 0;
}
4. Given initial amount and a yearly Interest rate calculate the amount of
money expected at the end of a period of not less than 5 years Assume
n=
Hint: A = P(1+r⁄n)nt
A=Amount of money expected
P=Initial amount
R=Interest Rate in percent
R=R/100
T=Time involved in years. 0.5 years is calculated as 6 months, etc.
A = P(1+r⁄n)nt
A = P(1+ (R/100)/n)nt
For example, if the initial amount is N100,000 and the yearly interest rate is 10%, and
the period is 5 years, the expected amount is N146,744.
A = 100,000(1 + (10/100)/1)5
A = 100,000(1.10)5
A = 146,744
#include <iostream>
int main()
{
double fee = 25000;
std::cout << "Year\t\tMembership Fee" << std::endl;
for (int year = 1; year <= 6; year++)
{
fee += fee * 0.04;
std::cout << year << "\t\t" << fee << std::endl;
}
return 0;
}
6. Write a program that should take two numbers (that is, first and last)
from the user and display all the numbers and their square in the form
of an ordered pair between the first and last numbers. For example, if a
user enters 2 to 5 then it should display pairs: (2.4) (3.9) (4.16) 15.25)
#include <iostream>
using namespace std;
int main()
{
int startnum, endnum;
cout << "Please enter two numbers (first and last): ";
cin >> startnum >> endnum;
for (int i = startnum; i <= endnum; i++){
cout << "(" << i << "," << i*i << ")" << endl;
}
7. Write a program in VB that should take 3 numbers from the user as input. Your
program should find and print the square and cube of these three numbers on the
screen.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Declare the three variables to store the input numbers
Dim num1, num2, num3 As Integer
'Read the three numbers from the user
num1 = TextBox1.Text
num2 = TextBox2.Text
num3 = TextBox3.Text
'Calculate the squares and cubes of the three numbers
Dim square1, square2, square3, cube1, cube2, cube3 As Integer
square1 = num1 * num1
square2 = num2 * num2
square3 = num3 * num3
cube1 = num1 * num1 * num1
cube2 = num2 * num2 * num2
cube3 = num3 * num3 * num3
'Print the results
MessageBox.Show("Square of " & num1 & " is " & square1 & vbCrLf & "Square of "
& num2 & " is " & square2 & vbCrLf & "Square of " & num3 & " is " & square3 &
vbCrLf & "Cube of " & num1 & " is " & cube1 & vbCrLf & "Cube of " & num2 & "
is " & cube2 & vbCrLf & "Cube of " & num3 & " is " & cube3)
End Sub
End Class