Posts

Showing posts from February, 2017

Averaging Score

Image
Suppose you have a class of ten students who took a quiz. The grades (integers in the range 0 to 100) for this quiz are made available to you. so this program tutorial shows us how to determine the class average on the quiz. What we need to understand about the class average is that it is equal to the sum of the grades divided by the number of students. so the algorithm below for solving this problem must input each grade, keep track of the total of all grades input, perform the averaging calculation and print the result. First of all we will need to use the pseudo code to list the actions to execute and specify the order in which these actions should execute. Pseudo code is an artificial and informal language that helps you develop algorithms. It’s useful for developing algorithms that will be converted to structured Java programs. They are not executed on computers; rather, they merely help you “think out” a program before attempting to write it in a programming l...

Temperature Conversion Program

Image
This program uses the switch statement to convert one temperature degree to another and also uses the JOptionPane input/output dialog box from the javax.swing. package to display the information. we also have to note that when inputting digits in java applications, it is entered as strings which can then be converted to corresponding data types like integers and floating point numbers. the program below illustrates temperature conversion program. import javax.swing.JOptionPane; public class Temperature{   public static void main(String args[])   {     String from;     String to;     String value;       int number1;     int number2;     double temp;       JOptionPane.showMessageDialog(null, "Temperature Conversion");       from = JOptionPane.showInputDialog("Enter no of unit to convert from: 1.Celcius 2. Farenheit 3. Kelvin");     to = JOpti...

Odd and Even

Image
Welcome in C programming, in this tutorial we will be looking at how to w rite a program that asks a user to input an integer and the program determines if the integer is odd or even. An  even number  is a  number  that can be divided into two equal groups. While an  odd number  is a  number  that cannot be divided into two equal groups.  We will be using the IF/ELSE statement to compare the  variable imputed by the user, so if "num" which is the variable name that holds the user input divides two (2) with no reminder, then its an even number, else its an odd number.  The program below, shows the step on how these is achieved. #include<stdio.h> #include<stdlib.h> int main(void) {     int num;      printf("Enter a number:");     scanf("%d", &num);      if(num%2==1){       ...

Simple Interest calculation

Image
In this C programming tutorial, i will be showing you how to write a program in C to calculate simple interest; and we are going to need an illustrated example to enable us get variable to use for the calculation.  So lets assume a person invests $4016.25 in a savings account yielding 9% interest; Assuming that all interest is left on deposit in the account, we are to write a program in C that calculates and prints the amount of money in the account at the end of each year for 5 years. Formula for calculating simple interest amount is:  a= p(1+r) n a= Amount  p= original amount(Principal),  r = Rate ,  n= Number of years. This problem involves a loop that performs the indicated calculation for each of the 5 years the money remains on deposit. We would also be using the  [pow]-Standard Library Function. The function pow(x,y) calculates the values of x raised to the yth power. The header <math.h> should always be included when...

Rolling a Six-Sided Die

Image
Welcome to C programming tutorial, we will be writing a program illustration that Rolls a Six-Sided. A fair  die  means that each of the faces has the same probability of landing facing up;  A standard  six - sided die , for example, can be considered "fair" if each of the faces has a probability of 1/6. The Program will be required to loop 20 times and on each loop the rand() function for number generation will be called to be picking numbers randomly between 1 to 6. #include<stdio.h> #include<stdlib.h> int main( void ) {     int i;     for (i=1; i<=20; i++){         printf("%5d", 1+(rand()%6));         if (i%5==0){             printf("\n");          }     }     return 0; ...

Using Do-While Repetition Statement

Image
A  do while loop  is a control flow  statement  that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block. this tutorial shows us how to use a do while repetition statement to break out loop. Now lets assume you are printing loads of data using this do while loop and you want it to stop at a particular point of mark, that is where the break statements comes in. The break statement are used to alter the flow of control, the break statement when executed in a do-while statement causes an immediate exit from that statement. The program below illustrates how to use the do-while statement. #include<stdio.h> int main(void) {     int x = 1;     do{ printf("%d", x);   if(x==1000){       break; } } while(x <=10000);             ...