DATA STRUCTURE AND ALGORITHM
(FOR CMU-CET STUDENTS)
INTRODUCING C LANGUAGE
• HISTORY OF C LANGUAGE
C Programming Language came out of Bell Labs in the
early 1970. Dennis Ritchie develop C Language according
to the Bell Labs paper. C Language was used for Unix
operating system. But before the C language development,
a B Programming was developed by Ken Thompson. Due
to slow nature of B in the Operating System this led to the
development of C.
PUBLICATION OF THE C PROGRAMMING LANGUAGE
• In 1978 Brian Kernighan and Dennis Ritchie published The C
Programming Language as a formal standard reference. Five
years later the American National Standard Institute (ANSI)
formed the committee X3J11 for standard C.
• Unix and Linux were written in C and Databases such Oracle,
MySQL, MS SQL Server partially written in C. Other programming
languages like Python and Perl use compilers that are written in
C.
• The language also made way for C++, Objective-C, C# and many
more C-based Languages that each have their own specialty.
Sample programs in C Language (disecting)
SAMPLE PROGRAM # 1
#include <stdio.h>
main()
{
printf(“Hello to today’s NEW NORMAL\n ”);
printf(“CMU-CET face the challenge of On-line Education!”);
return 0;
}
Output:
Hello to today’s NEW NORMAL
CMU-CET face the challenge of On-line Education!
DISECTING:
- #include is a preprocessor command that tells the compiler to include the
contents of stdio.h (standard input/output.header)
-stdio.h file contains functions such as scanf() and and printf() function.
-main() - the execution of a C programs starts from main() function.
-{ - start the body of the program
-printf() function - to display Hello to today’s NEW NORMAL
-printf() function- to display CMU-CET face the challenge of On-line
Education!
-return 0; - Exit Status
-} - end body of the program
Program using SCANF AND PRINTF FUNCTION
SAMPLE PROGRAM # 2
#include <stdio.h>
int main()
{
int num1;
printf(“enter a number: “);
scanf(“%d”, &num1);
printf(“you enter number: “,num1);
return 0;
}
Declaration of DATA TYPE and VARIABLE
SAMPLE PROGRAM #3
#include <stdio.h>
int main()
{
char Sname;
int quiz1, quiz2;
printf(“Please input your name: “);
scanf(“%c”,&Sname);
printf(“Input your first quiz: “);
scanf(“%d”,&quiz1);
printf(“Your first quiz score is %d : “,quiz1);
printf(“Input your second quiz: “);
scanf(“%d”,&quiz2);
printf(“Your second quiz score is %d : “,quiz2);
return 0;
}