Software or Program
There are two components in computer system. First is Hardware and Another is software. Hardware is the parts of computer that can be touched and software is the part of computer system that can not be touched. The program that is contained in the computer memory is called software. In simple Software is the knowledge of computer system. Software is also called program. Creating or writing a program or software is called programming and the language in which we write a program is called programming language. There are many types of programming language but all of them are categorized under there groups.
1. machine level language
2. assembly level language
3.
machine level language is the code in binary number system and also arranged as hexadecimal code. They are very hard to write and understand since one character or alphabet contains long binary code.
Assembly level language is little bit easy than machine level language. It is used to achieve pin and port of hardware like processor and micro-controller .
On the other hand high level programming language is the language that is user friendly and easy to write and understand. There are various high level programming language like C, C++, C#, java , oracle, python etc. But we will discuss here only C and C++.
Introduction to C
According to wikipedia
C (/ˈsiː/, as in the letter c) is a general-purpose, imperative computer programming language, supporting structured programming,lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging fromsupercomputers to embedded systems.
C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs,[5] and used to re-implement the Unix operating system.[6] It has since become one of the most widely used programming languages of all time,[7][8] with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by theAmerican National Standards Institute (ANSI) since 1989 (see ANSI C) and subsequently by the International Organization for Standardization (ISO).
sample programs
1. hello world program
step 1-- install code blocks
step 2-- open code blocks
step 3-- go to file>new file>empty file
step 4-- write the following code in green colour
#include<stdio.h> // it is preprocessor directives and it directs the program to the header file stdio.h
int main() // start of main function .
{
printf("hello world"); // printf is the function which displays the content written in double quotation } mark.
int main() // start of main function .
{
printf("hello world"); // printf is the function which displays the content written in double quotation } mark.
step 5-- build and run the program by saving it.
Output
then click build and run option . you have to save the program first and then the program will run giving output like this
2. Program to add two numbers
here is a program to add two numbers using c language in code blocks.
step 1-- open code blocksstep 2-- write the code below in green color in code blocks
#include<stdio.h>
int main()
{
int x=5; //initialize x =5 of integer type
int y=15; //initialize y=15 of integer type
int sum; // new variable declaration
sum= x+y; // add x and y and result is stored in sum variable
printf("The sum is %d \n",sum); // sum result is printed . %d means integer type
}
3. by asking value of x and y and adding them
#include<stdio.h>
int main()
{
int x,y,sum; //declares three variables x y and sum of integer types
printf("enter the value of x \n \n"); // prints asking value
scanf("%d",&x); // stores the value entered by user as x
printf("enter the value of y \n \n"); // ask the value of y
scanf("%d",&y); // stores the value entered by user as y
sum= x+y; // add x and y value and stores it in sum variable
printf("The sum of %d and %d is %d \n",x,y,sum); // display result. . %d are in order of variable
}
output
4. program to find factorial of a number
#include <stdio.h>
int main()
{
int i, n, factorial = 1;
printf("Enter a number to calculate it's factorial\n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
factorial = factorial * i;
printf("Factorial of %d = %d\n", n, factorial);
return 0;
}
No comments:
Post a Comment