C is a Language used from 1970. Developed by Dennis Reitchie.
It's is known as the Middle level language. As it is not a High Level and a Low level language. But a language in between them. While developing this Dennis never think that it will be a Language for All. This happen as it is very simple and had small library, due to which any one can learn it easily.
The C programming language was devised in the early 1970s by Dennis M. Ritchie an employee from Bell Labs (AT&T).
In the 1960s Ritchie worked, with several other employees of Bell Labs (AT&T), on a project called Multics. The goal of the project was to develop an operating system for a large computer that could be used by a thousand users. In 1969 AT&T (Bell Labs) withdrew from the project, because the project could not produce an economically useful system. So the employees of Bell Labs (AT&T) had to search for another project to work on (mainly Dennis M. Ritchie and Ken Thompson).
Program in C :
Note :-> A C Program contains functions and variables. The functions specify the tasks to be performed by the program. The above program has one function called main. This function tells your program where to start running. main functions are normally kept short and calls different functions to perform the necessary sub-tasks. All C codes must have a main function.
Note :-> The main, {} brackets, comments, and include should be familiar. The new part of this program is the scanf, variables, and the use of printf to print out numbers. of this program that we haven't seen before.
Note :-> The C language takes a lot of flack for its ability to peek and poke directly into memory. This gives great flexibility and power to the language, but it also makes it one of the great hurdles that the beginner must have in using the language. Arrays are very interesting since they can be accessed through pointers or array syntax, that is why they are grouped into the same lesson.
For information don't forget to check site.........
Program in C :
/* hello world program */ #include "stdio.h" void main() { printf("\n Hello World\n"); // print to screen }
Note :-> A C Program contains functions and variables. The functions specify the tasks to be performed by the program. The above program has one function called main. This function tells your program where to start running. main functions are normally kept short and calls different functions to perform the necessary sub-tasks. All C codes must have a main function.
#include <stdio.h> void main() { int numcandy; // declare a number variable double cost; // declare a variable that can store decimals printf("How many lollipops do you want: "); scanf("%d", &numcandy); // get input from user cost = 0.55 * numcandy; // do some math printf("\nPlease pay %f to the cashier!\n", cost); }
Note :-> The main, {} brackets, comments, and include should be familiar. The new part of this program is the scanf, variables, and the use of printf to print out numbers. of this program that we haven't seen before.
#include <stdio.h> #define START_NUMBERLOLLIPOPS 100 #define MAX_AT_ONCE 30 void main() { int numcandy; double cost; int numberlollipopps; double totalcost; numberlollipopps = START_NUMBERLOLLIPOPS; // set start value to our constant totalcost = 0; while (numberlollipopps > 0) { printf("(%d left) How many lollipops do you want (-1 quits): ", numberlollipopps); scanf("%d", &numcandy); if (numcandy == -1) // since this if has only one statement brackets are not needed break; // exit out of the while loop else if (numcandy > MAX_AT_ONCE || numcandy <= 0 || numcandy > numberlollipopps) { printf("You cannot have that many, enter another number\n"); } else { cost = 0.55 * numcandy; printf("\nPlease pay $%.2f to the cashier!\n", cost); totalcost = totalcost + cost; numberlollipopps = numberlollipopps - numcandy; } } printf("All the lollipopps have been sold for : $%.2f\n", totalcost); }
Note :-> The C language takes a lot of flack for its ability to peek and poke directly into memory. This gives great flexibility and power to the language, but it also makes it one of the great hurdles that the beginner must have in using the language. Arrays are very interesting since they can be accessed through pointers or array syntax, that is why they are grouped into the same lesson.
#include <stdio.h> void exchange ( int *a, int *b ) { int temp; temp = *a; *a = *b; *b = temp; printf(" From function exchange: "); printf("a = %d, b = %d\n", *a, *b); } void main() { /* RIGHT CODE */ int a, b; a = 5; b = 7; printf("From main: a = %d, b = %d\n", a, b); exchange(&a, &b); printf("Back in main: "); printf("a = %d, b = %d\n", a, b); }
For information don't forget to check site.........
No comments:
Post a Comment