Bigsemite enjoys exchanging ideals with colleagues. Most of my friend and
some others bring questions on different course and Bigsemite uses the available
resource to solve the problem.
If you've been battling with particular Module, subroutine, function or you are
encontering problem on your software design, you too can submit your Task with
some explanation so that we exchange ideals in other to move forward. Let's
share knowledge with each other
The following are few of the simple questions asked by some
people.
Some questions on Data Processing
Question: Write a program to compute Average of
numbers. -Adelabu Lukman, University of Ado-Ekiti
Solution
QBASIC
Input "How many Nos?", N
S=0
For I=1 to N
Input "Enter a No."; K
Let S=S + K
next I
Let A = S/N
Print "Average = ",A |
C- Language
#include<stdio.h>
main()
{
int n,i,k,s,a;
s=0;
printf("How many Nos?");
scanf("%d",&n);
for (i=1; i<=n; i++)
{
printf("\nEnter a no.?");
scanf("%d",&k);
s+=k;
}
a=s/n;
printf("\nAverage = %d", a);
Return 0;
}
|
FORTRAN
INTEGER N, I, K, S, A
Read (*,*) N
DO 10 I=1, N
Read(*,*) K
S=S + K
10 CONTINUE
A= S/N
Write(*,*) 'Average = ',A
End
|
Using Visual solutions (Visual Basic and Visual C++)
Having the form designed as above, Then insert the following code on clicking
each command button:
Visual Basic
Module
Public s, n
s=0: n=0
Sub Okbutton()
s = s + m_no.text
n= n + 1
m_no.text= 0
End sub
Sub Onsolve()
m_av.text = s / n
End sub
Sub Onrefresh()
s=0: n=0: m_no.text=0: m_av.text=0
End sub
|
Visual C++
global int n, s;
n=0;
s=0;
Okbutton()
{
UpdateData(True);
s+=m_no;
n++;
m_no=0;
UpdateData(False);
}
Onsolve(){
m_av = s /n;
UpdateData(False);
}
Onrefresh(){
m_av=0: m_no=0: s=0: n=0;
UpdateData(False); } |
Question: Write a program to Calculate the
Roots of a Quadratic Equation - Adepoju Akeem, Federal
Polytechnics Offa, Nigeria
Solution
Using Almighty Formula X = (-B+-SQR(B2 - 4AC))/(2A)
VISUAL BASIC
Sub onsolve()
a1= A.text
b1=B.text
c1=C.text
D=b1*b1 - 4 * a1 * c1
if D<0 Then
'Complex Root
X1.text = -b1/(2*a1)
X2.text = (-SQR(-D)) & "i"
Elseif D=0 Then
X1.text = b1/(2*a1)
X2.text=X1.text
Else
X1.text=(-b1+SQR(D))/(2*a1)
X2.text=(-b1-SQR(D))/(2*a1)
End if
End sub
|
C-Language
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c,x1,x2;
printf("\nEnter the value of A, B, C");
scanf("%d %d %d", &a, &b, &c);
d = b**2-4*a*c;
if (d<0){
//Complex Root
x1= -b/(2*a);
x2= (-d)**0.5;
}
if (d=0)
{//Equal roots
x1= -b/(2*a);
x2=x1; }
if (d>0)
{//Normal Quadratic
x1= (-b + sqrt(d))/(2*a);
x2= (-b-+ sqrt(d))/(2*a); }
printf("\n The 1st root is %d\n2nd root is %di",x1,x2);
return 0;
}
|
FORTRAN
INTEGER A, B,C, X1, X2
READ(*,*) A, B, C
D= B*B -4*A*C
IF (D .LT. 0) THEN
X1= -B/(2*A)
X2 = SQRT(-D)
ELSE IF (D .EQ. 0) THEN
X1 = -B/(2*A)
X2 = X1
ELSE
X1 = (-B+SQRT(D))/(2*A)
X2 = (-B-SQRT(D))/(2*A)
END IF
WRITE(*,10) X1, X2
10 FORMAT('1ST ROOT IS ',I2,' 2ND ROOT IS ',I2)
END
|
In case if you try any of the solution above and it doesn't work, do not shake,
are you sure you did not make any syntax Error while typing the code?
Are you sure you are using the right compiler for the correct code? For example,
Visual Basic coding may not work with QBasic Compiler/interpreter.
If you are free of all faults, then you can send your complain to bigsemite.
Click below.
Meet with Bigsemite let's share knowledge with each other. Click below:
|