CLanguage
Tutor
© Ajani Dele
All rights reserved. No part of this material may be
reproduced, stored in a retrieval system or transmitted in any form or by any
means electronic, electrical, recording or otherwise without the permission of
the copyright owner.
Introduction
The C programming language was
originally developed by Dennis Ritchie of Bell Laboratories, and was designed
to run on a PDP-11 with a UNIX operating system. Although it was originally intended
to run under UNIX, there was a great interest in running it on the IBM PC
compatibles, and other systems. C is excellent for actually writing system
level programs, and the entire Applix 1616/OS operating system is written in C
(except for a few assembler routines).It is an excellent language for this
environment because of the simplicity of expression, the compactness of the
code, and the wide range of applicability.
C is a general-purpose programming
language. It has been closely associated with the UNIX operating system where
it was developed, since both the system and most of the programs that run on it
are written in C. The language, however, is not tied to any one operating
system or machine; and although it has been called a “system programming
language” because it is useful for writing compilers and operating systems, it
has been used equally well to write major programs in many different domains.
C provides the fundamental control-flow
constructions required for well-structured programs: statement grouping,
decision making (if-else), selecting one of a set of possible
values (switch), looping with the termination test at the top (while, for) or at the bottom (do), and
early loop exit (break).
Functions may return values of basic
types, structures, unions, or pointers. Any function may be called recursively.
Local variables are typically ``automatic'', or created anew with each
invocation. Function definitions may not be nested but variables may be
declared in a block-structured fashion. The functions of a C program may exist
in separate source files that are compiled separately. Variables may be
internal to a function, external but known only within a single source file, or
visible to the entire program.
A preprocessing step performs macro
substitution on program text, inclusion of other source files, and conditional
compilation.
C is a relatively “low-level” language.
This characterization is not pejorative; it simply means that C deals with the
same sort of objects that most computers do, namely characters, numbers, and
addresses. These may be combined and moved about with the arithmetic and
logical operators implemented by real machines.
C provides no operations to deal
directly with composite objects such as character strings, sets, lists or
arrays. There are no operations that manipulate an entire array or string,
although structures may be copied as a unit. The language does not define any
storage allocation facility other than static definition and the stack
discipline provided by the local variables of functions; there is no heap or garbage
collection. Finally, C itself provides no input/output facilities; there are no
READ or WRITE statements, and no built-in file access methods. All of these
higher-level mechanisms must be provided by explicitly called functions. Most C
implementations have included a reasonably standard collection of such
functions.
Similarly, C offers only
straightforward, single-thread control flow: tests, loops, grouping, and
subprograms, but not multiprogramming, parallel operations, synchronization, or
coroutines.
let's see some written programmes
C program to sum the square of
number using functions.
int sum;
/* this is a global variable*/
main( )
{
int index;
header();
/* this calls the function named header*/
for (index = 1;index <= 7;index++)
square(index); /* This calls the square function*/
ending();
/* This calls the ending function*/
}
header()
/* This is the function named header */
{
sum = 0;
/* initialize the variable "sum" */
printf("This is the header for the square
program\n\n");
}
square(number)
/* This is the square function*/
int number;
{
int numsq;
numsq = number * number;
/* This produces the square*/
sum += numsq;
printf("The square of %d is
%d\n",number,numsq);
}
ending()
/* This is the ending function*/
{
printf("\nThe sum of the squares is
%d\n",sum);
}
C PROGRAM FOR QUADRATIC EQUATION
/*
real roots of a quadratic equation*/
#include <stdio.h>
#include <math.h>
Main()
{
float
a, b, c, d, x1, x2;
/*
read input data*/
Printf(“a=”);
Scanf(“%f”,
&a);
Printf(“b=”);
Scanf(“%f”,
&b);
Printf(“c=”);
Scanf(“%f”,
&c);
/*carry
out the calculation */
d=sqrt(b*b
– 4*a*c);
printf(“a=%e
b=%e c=%e d=%e\n”, a, b, c, d);
printf(“-b+d=%e\n”,
(-b+d));
printf(“-b-d=%e\n”,
(-b-d));
x1 = (-b+d)/(2*a);
x2 = (-b-d)/(2*a);
/*display
the output*/
Printf(“\nx1
= %e x2 = %e”, x1, x2);
return
0;
}
C
program which reads angle in radians and then prints equivalent angle in
degree, minute and seconds.
#include<stdio.h>
#define pi
3.142
int main()
{
float r;
int d, m, s;
printf(“Enter
angle in radian\n”);
scanf(“%f”,
&r);
r=(r*180)/pi;
d=r;
r=(r-d)*60;
/*calculating left over angle in minute*/
m=r;
s=(r-m)*60;
printf(“%d%d%d\n”,
d, m, s);
return 0;
}
C
program that read in angle in degree, minute, and seconds then print the
equivalent in radian
#include
<stdio.h>
int
main()
{
int
d, m, s;
float
rad;
printf(“enter
angle in degree, minutes, and seconds”);
/*reading
angle in degrees, minutes, and seconds*/
Scanf(“%d%d%d”,
&d, &m, &s);
rad
= (d+(m/60.0)+(s/3600.0))*(3.14/180);
/*converting
angle into radians*/
Printf(“%f\n”,
rad);
return
0;
}
C program to calculate the potential energy of
a body
#include
"stdafx.h"
#include
"stdio.h"
#include
"stdlib.h"
//#include
"math.h"
int main ()
{
float pe, m,h;
char c;
const float g = 9.8;
printf("Enter the value for m and h"); /* reading
in d value */
scanf("%f", &m);
scanf("%f", &h);
pe = (m * g * h); /*
computation takes place here */
/* display result */
printf("mass=%f\n",m);
printf ("height=%f\n", h);
printf("PE=%-7.4f\n", pe);
c = getchar();
system ("pause");
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
int main ()
{
printf("C programming Give Birth to Object
oriented language");
getchar();
system("pause");
return
0;
}
TO GET THE FULL PAPER
CONTACT CROSSDEE
OR PAY TO ANY OF THIS BANK
WEMA BANK
FIRST BANK
ECO BANK
note: for the Account
Number send email to ajanidele@gmail.com
No comments:
Post a Comment