Posts

Factorial Calculation in C++ Using recursive method

Image
In this C++ program, we will be using recursive method to calculate factorial from 0 through 10. A recursive method is a method that calls itself either directly or indirectly through another method. A recursive declaration of the factorial method is  n! = n.(n-1)! with that given, the source code below illustrates just how recursive methods works. #include <iostream> double factorial( double number) using namespace std; int main() {     for(int counter = 0; counter <= 10; counter++)     cout <<counter<<"! = "<<factorial(counter)<<"\n"<<endl;     return 0; } double factorial(double number) {     if(number <= 1)         return 1;     else         return number * factorial(number - 1); }  

C Program to Guess a Number

Image
From  Deitel C how to program (Making a difference) This is a carefully sort out source of in c program that plays "guess the number" as follows: The program chooses the number to be guessed by selecting a random integer in the range 1 to 1000.. The player types a first guess and presses the Enter key. If the player guess is incorrect, the program displays 'Too high.Try again or Too Low. Try again. When the user enters the correct answer, displays 'Congratulations. You guessed the number! We will basically be using the IF Statements to compare user input to determine if it matches the random generated number. So we  use the if statement to determine if the number input by the user is correct else the program either prints out too high or too low.  #include <stdio.h> #include <stdlib.h> #include <time.h>  int  main(void) {     int a=0, b=0;     int choice; srand(time(NULL));     a = 1 ...

Displaying Text in a Dialog Box

Image
In this program, will we be showing you how to use JAVA program to display a text using JAVA GUI (Graphics User Interface) in a dialog box. Typically,dialog boxes are windows in which programs display important messages to the user of the program.  This application uses Java's Class JOptionPane which provides prepackaged dialog boxes that enables programs to display windows containing messages to its user. we will be using the  import  javax.swing. JOptionPane which  is an import declaration and is part of the  Java API .  Programmers use import declarations to identify the predefined classes used in Java Program. The import declaration help the compiler locate the classes you intend to use, this tells the compiler that our program uses class JOptionPane from package javax.swing and this package helps programmers create graphical user interfaces (GUI) for applications. The program below illustrates how to create a text in a dialog box...

Printing Your First Java Program

Image
Every programmer first code or writing starts with words like "Hello World", "Am a Programmer" etc, that's what makes programming so fun and interesting in a way that the programmer would one day be writing millions of lines of codes. But before you start writing thousands and millions of codes we have to start from somewhere and that is why this post is very essential to beginners new to coding.  We will be demonstrating how to write "Welcome to Java programming" in a Java language. Java language is one of the most widely used high level programming languages for developing complex and high end applications that can be run on all platforms. thus; its platform independent.  To get started with Java, I recommend using DrJava which is a lightweight development environment for writing Java programs. It is designed primarily for students, providing an intuitive interface and the ability to interactively evaluate Java code. It also incl...

Printing Your First C++ Program

Image
Welcome to C++ If you are here, it means you have taken a very big step to a very lucrative journey ahead to become one of those with super powers of coding, and what better way to start than with C++ I won't bore you with much talk cause this blog is all about codes and codes, but before you start coding in C++ you require an IDE (Integrated Device Environment) which will assist you in writing and running your C++ programs. I would recommend   Code::Blocks with gnu gcc compiler (Which supports C programming Language too), which is the best compiler to start  with for beginners and which i like using most.  To make use of the IDE, install and open the code blocks,  Write the  C++  code and save the file with . cpp  extension. To save the file, go to File > Save (Shortcut: Ctrl + S). To run the program, go to Build > Build and Run. Now let's go ahead with what brought you here which is  writing your first C++ code. The code below...

Printing Your First C Program

Image
Welcome to C If you are here, it means you have taken a very big step to a very lucrative journey ahead to become one of those with super powers of coding, and what better way to start than with C To get started with C you need an IDE. Install the Code::Blocks with gnu gcc compiler, which is the best compiler to start  with for beginners. Write the  C  code and save the file with . c  extension. To save the file, go to File > Save (Shortcut: Ctrl + S). To run the program, go to Build > Build and Run. Now let's go ahead with what brought you here which is  writing your first C++ code.  The code below illustrates just how to do that. This application displays a line of text in a Command prompt using an IDE   #include <stdio.h>   int main( void )   { printf( "Welcome to C!\n" );   } see also Printing Your First C++ Program

Arithmetic, Smallest and Largest

Image
We will be writing an application that  inputs three integers from the user and displays the sum, average, product, smallest and largest of the numbers using a java application GUI (Graphics User Interface) So the first step of the program will be to import javax.swing.JOptionPane which is part of the java packages and which has the capability of displaying and inputting text in dialog box. usually 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 code below illustrates how to do a simple arithmetic, smallest and largest of three numbers. import javax.swing. JOptionPane ; public class Arithmetic {   public static void main( String args [])   {     String firstNumber;     String secondNumber;     String thirdNumber;     String compare;       int number1; ...