Cobol Programming Language: Hello, World
Cobol Programming Language: Hello, World
The equivalent construct in many procedural languages would be age = age + years This syntax is similar to the compound assignment operator later adopted by C: age += years The abbreviated conditional expression IF SALARY > 8000 OR SUPERVISOR-SALARY OR = PREV-SALARY is equivalent to IF SALARY > 8000 OR SALARY > SUPERVISOR-SALARY OR SALARY = PREV-SALARY
Hello, world
An example of the "Hello, world" program in COBOL: IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. PROCEDURE DIVISION. DISPLAY 'Hello, world'. STOP RUN. Like any widespread programming language, there are various dialects of COBOL. Some compilers, for example, allow the use of double quotes in addition to standard single quotes: DISPLAY "Hello, world".
program average
! As written, if there are no data points, an average of zero is returned ! While this may not be desired behavior, it keeps this example simple
implicit none
real, dimension(:), allocatable :: points integer real negative_average=0. :: number_of_points :: average_points=0., positive_average=0.,
allocate (points(number_of_points))
! Take the average by summing points and dividing by number_of_points if (number_of_points > 0) average_points = sum(points) / number_of_points ! Now form average over positive and negative points only if (count(points > 0.) > 0) then positive_average = sum(points, points > 0.) / count(points > 0.) end if if (count(points < 0.) > 0) then negative_average = sum(points, points < 0.) / count(points < 0.) end if deallocate (points)
! Print result to terminal write (*,'(a,g12.4)') 'Average = ', average_points write (*,'(a,g12.4)') 'Average of positive points = ', positive_average write (*,'(a,g12.4)') 'Average of negative points = ', negative_average
Recall from the beginning of this text the demonstration program duplicated below: #include <stdio.h>
C PROGRAMMING LANGUAGE
In computing, C (/si/, like the letter C) is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 atBell Labs. Its design provides constructs that map efficiently to typical machine instructions, and therefore it found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system. C is one of the most widely used programming languages of all time, and there are very few computer architectures for which a C compiler does not exist. Many later languages have borrowed directly or indirectly from C, including: C#, D, Go, Java, JavaScript, Limbo, LPC, Perl, PHP, Python, and Unix's C Shell. The most pervasive influence on these languages has been syntactical, and they tend to combine the recognizable expression and statementsyntax of C with underlying type systems and data models that can be radically different. C++ started as a preprocessor for C and is currently nearly a superset of C.
int main(void) { printf("Hello, world!\n"); return 0; } If you compile and run this program, you will see the sentence below show up on your screen:
Hello, world!
A typical application might be like this: #include "stdio.h" int main(void) { int a; printf("Please input an integer value: "); scanf("%d", &a); printf("You entered: %d\n", a); return 0; } The correct usage would be:
scanf("%s", a);
Sample
10 INPUT "What is your name: ", U$ 20 PRINT "Hello "; U$ 30 INPUT "How many stars do you want: ", N 40 S$ = "" 50 FOR I = 1 TO N 60 S$ = S$ + "*" 70 NEXT I 80 PRINT S$ 90 INPUT "Do you want more stars? ", A$ 100 IF LEN(A$) = 0 THEN GOTO 90 110 A$ = LEFT$(A$, 1) 120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30 130 PRINT "Goodbye "; U$ 140 END The resulting dialog might resemble:
What is your name: Mike Hello Mike How many stars do you want: 7 ******* Do you want more stars? yes How many stars do you want: 3 *** Do you want more stars? no Goodbye Mike