C++ Show Growing Letter Count ABCDEF

email me
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
int beginLetter = 65;

int letterCount = 6;

for (int i = 1; i <= letterCount; i++)
{
for (int j = 1; j <= i; j++)
{
cout << char(beginLetter);
beginLetter++;
}
cout << endl;
beginLetter = 65;
}
cin.get();
return 0;
}

Output

Notes

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
int beginLetter = 65;
int n;
cout << "Enter height: " << endl;
cin >> n;

for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
cout << char(beginLetter);
beginLetter++;
}
cout << endl;
beginLetter = 65;
}
cin.get();
cin.get();
return 0;
}

Fortran – Subroutines and Iteration

email me

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi, simplyfortran-2.35.msi; also, try the online Fortran compiler.

PROGRAM MAIN

! inhibit older feature
IMPLICIT NONE
    
    ! declare numbers    
    INTEGER N, X
    
    ! declare sub    
    EXTERNAL SUB1
    
    ! declare global variable
    COMMON /GLOBALS/ N
    
    ! set initial value
    X = 0
    
    ! input how many interations
    PRINT *, 'Enter number of interations: '
    READ (*,*) N
    
    ! goto sub1
    CALL SUB1(X,SUB1)
    
    ! end program
    END

    ! our sub
    SUBROUTINE SUB1(X,LOOP)
        INTEGER N, X
        EXTERNAL LOOP
        COMMON /GLOBALS/ N
    
        IF(X .LT. N)THEN
            X = X + 1
            PRINT *, 'x = ', X
            CALL LOOP(X,LOOP)
        END IF
        ! end if
    
    ! end sub
    END

 

Output

 

Notes

Learn more, Fortran language

https://pinetools.com/syntax-highlighter

 

Types of Variables

Integer: It can hold only integer values.

Real: It stores the floating point numbers.

Complex: It is used for storing complex numbers.

Logical: It stores logical Boolean values.

Character: It stores characters or strings.

Fortran – Perform Sum of Given Numbers

email me

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi, simplyfortran-2.35.msi; also, try the online Fortran compiler.

PROGRAM Sum

! inhibit older feature
IMPLICIT NONE

	! declare numbers
    REAL X,Y,Z
	
	! input X
    PRINT *,"Enter first number: "
    READ *, X
	
	! input Y
    PRINT *,"Enter second number: "
    READ *, Y
    
	! perform calculation
	Z = X + Y
	
	! output sum
    PRINT *,"Sum of X + Y = ", Z
	
	READ(*,*)
	
END PROGRAM Sum

 

Output

 

Notes

Learn more, Fortran language

https://pinetools.com/syntax-highlighter

 

Types of Variables

Integer: It can hold only integer values.

Real: It stores the floating point numbers.

Complex: It is used for storing complex numbers.

Logical: It stores logical Boolean values.

Character: It stores characters or strings.

C++ Show Growing and Shrinking Number Set

email me
#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
int a, length;
printf("Enter length: ");
cin >> length;
a = length / 2;

for (int b = 1; b <= a; b++)
{
for (int c = 1; c <= b; c++)
{
cout << c;
}

cout << endl;
} for (int e = a-1; e >= 1; e--)
{

for (int d = 1; d <= e; d++)
{
cout << d;
}

cout << endl;
}

cin.get();
cin.get();
}


Output

C++ Return Binary from 1-256

email me

#include "stdafx.h"
#include <iostream>

using namespace std;

int binary(int x) {
int arr[99], mod, quo, i = 1, ctr = 0, sum = 0;
do {
mod = x % 2;
arr[ctr] = mod;
quo = x / 2;
x = quo;

arr[ctr] *= i;
sum += arr[ctr];
ctr++;
i *= 10;
} while (x != 0);
return sum;
}

int main() {
int arr[256], index = 0;
for (int i = 1; i <= 256; i++) {
arr[index] = binary(i);
index++;
}
for (index = 0; index < 256; index++) {
// output
cout << index+1 << ": " << arr[index] << endl;
}

cin.get();
return 0;
}

Output

Fortran – Create Array and Sort Given Numbers

email me

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi,  simplyfortran-2.35.msi; also, try the online Fortran compiler.

dimension a(100)

! declare strings
character(LEN=18) :: strLine1
character(LEN=24) :: strLine2

! set strings
strLine1 = "Enter array size: "
strLine2 = "Enter numbers in array: "

! display string 1
PRINT *, strLine1

! input 1
write(*,*)
read(*,*)n

! display string 2
PRINT *, strLine2

! input 2
write(*,*)
read(*,*)(a(i),i=1,n)

! sort
do i=1,n-1
    do j=i+1,n
        if (a(i).gt.a(j)) then
            t=a(i)
            a(i)=a(j)
            a(j)=t
        end if
    end do 
end do

write(*,*)
write(*,*) (a(i),i=1,n)

read(*,*)
stop
end

 

Output

 

Notes

Learn more, Fortran language

https://pinetools.com/syntax-highlighter

 

Types of Variables

Integer: It can hold only integer values.

Real: It stores the floating point numbers.

Complex: It is used for storing complex numbers.

Logical: It stores logical Boolean values.

Character: It stores characters or strings.

Fortran – List Prime Numbers 1-100

email me

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi,  simplyfortran-2.35.msi; also, try the online Fortran compiler.

PROGRAM  Primes
IMPLICIT NONE
   
   ! declare integers
   INTEGER  :: Range, OptimusPrime, Divisor   
   
   ! declare strings
   CHARACTER(LEN = 15) :: strLine1
   
   ! set string 
   strLine1 = 'Prime numbers: '

   ! display string
   PRINT *, strLine1
   PRINT *, " "
      
   ! set range value
   Range = 100
   
   ! evaluate for prime number
   DO OptimusPrime = 3, Range, 2
      Divisor = 3                    
      DO
         ! not prime
         IF (Divisor*Divisor > OptimusPrime .OR. MOD(OptimusPrime,Divisor) == 0)  EXIT
         Divisor = Divisor + 2          
      END DO   

      IF (Divisor*Divisor > OptimusPrime) THEN         
         ! display prime
         PRINT *, OptimusPrime
      END IF
   END DO

READ(*,*)

! end program
END PROGRAM  Primes

 

Output

 

Notes

Learn more, Fortran language

https://pinetools.com/syntax-highlighter

 

Types of Variables

Integer: It can hold only integer values.

Real: It stores the floating point numbers.

Complex: It is used for storing complex numbers.

Logical: It stores logical Boolean values.

Character: It stores characters or strings.

Fortran – Hello World

email me

Recommended Reading (click for Amazon link)

 

I used the registered version of the Simply Fortran compiler, here: simplyfortran-3.0.msi,  simplyfortran-2.35.msi; also, try the online Fortran compiler.

Code

PROGRAM HelloWorld

! inhibit older feature
IMPLICIT NONE

    ! declare string
    CHARACTER(LEN = 13) :: strLine1
    
    ! set string
    strLine1 = "Hello, World!"
    
    ! display string
    PRINT *, strLine1

    READ(*,*)
    
! end program
END PROGRAM HelloWorld

 

Output

 

Notes

Learn more, Fortran language

Syntax Highlighter

C++ Print Cascading Alphabet Table (Vigenere Square)

email me

In cryptography, the tabula recta (from Latin tabula rēcta) is a square table of alphabets, each row of which is made by shifting the previous one to the left. The term was invented by the German author and monk Johannes Trithemius in 1508, and used in his Trithemius cipher. (wiki)

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
#include <string>

int main()
{
int a[26], aux, al = 65;

using std::string;

for (int i = 0; i<26; i++)
{
a[i] = al;
al++;
}

while (true) {
for (int j = 0; j < 26; j++)
{
printf("%c ", a[j]);
}
printf("\n");

for (int k = 0; k < 25; k++)
{
aux = a[k];
a[k] = a[k + 1];
a[k + 1] = aux;
}
if (a[0] == 65)
{
break;
}
}

std::cin.get();
return 0;

}

Output

Notes

https://en.wikipedia.org/wiki/Tabula_recta
https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher