Language c Basics

May 11, 2017 | Author: aashishanshu | Category: N/A
Share Embed Donate


Short Description

C Language Basics Including Programmes...

Description

‘C’ Language What is Language? Language is a medium of communication. There are several types of languages like: 1. Low Level Language: - Low level language is used to design system software and utilities etc. 2. High Level Language: -High level language is used to design the application software like Business Problems and Scientific problem.

What is C? C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Denis Ritchie. The C Compilers combines the capabilities of an assembly language with the feature of a high-level language and therefore it is well suited for writing both system software and business package. There are only 32 keywords and its strength lies its built-in functions.

Constants Constant in C refer to fixed value that do not change during the execution of a program. This quantity can be stored at a location in the memory of the computer.

Types of C Constants C constants can be divided into two major categories: 1. Primary Constants a) Integer Constants b) Real Constants c) Character Constants 2. Secondary Constants a) Array b) Pointer c) Structure d) Union etc.

Rules for Constructing Integer Constants a) b) c) d) e)

An integer constant must have at least one digit. It must not have a decimal point. It could be either positive or negative. No commas or blanks are allowed within an integer constant. The allowable range for integer constants is -32768 to +32767.

Rules for Constructing Real Constants a) b) c) d)

An integer constant must have at least one digit. It must have a decimal point. It could be either positive or negative. No commas or blanks are allowed within an integer constant.

Rules for Constructing Character Constants a) A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas; both the inverted commas should point to the left. b) The maximum length of a character can be 1 character.

Variables In C a quantity which may vary during program execution is called a variable. Variable names are given to locations in the memory of computer where different constants are stored. These locations can store integer, real or character constants.

Rules for Constructing Variable Names a) A variable name is any combination of 1 to 8 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 40 characters, still, it would be safer to stick to the rule of 8 characters. b) The first character in the variable name must be an alphabet. c) No commas or blanks are allowed within a variable name. d) No special symbol other that an underscore can be used in a variable name.

C Keywords Every C word is classified as either a keyword or an identifier. All keywords have fixed meanings and these meaning cannot be changed. Keywords serve basic building blocks for program statements. There are 32 Keywords available in C. auto case const short

double enum float void

if long register do

static switch union goto

break char continue signed

else extern return while

int near default far

struct typedef for unsigned

/*for simple addition, subtraction, multiplication and division*/ #include #include void main() { int a,b,c; clrscr(); printf("enter the value of a and b"); scanf("%d%d",&a,&b); c=a+b; printf("total=%d",c); c=a-b; printf("Subtraction=%d",c); c=a*b; printf("Multiplication=%d",c); c=a/b; printf("Division=%d",c); getch(); } /*for simple and compound interest*/ #include #include #include void main() { int p,r,t,si,ci; clrscr(); printf("enter the value of principle,rate of interest,number of years"); scanf("%d%d%d",&p,&r,&t); si=(p*r*t)/100; printf("simple interest=%d",si); ci=p*pow((100+r)/100.0,t)-p; printf("compound interest=%d",ci); getch(); } /*program to find out area of a triangle*/ #include #include void main() { int b,h,area; clrscr(); printf("enter the value of breadth and height"); scanf("%d%d",&b,&h); area=(b*h)/2; printf("area of triangle is:%d",area); getch(); } /*program to find out largest number in given two numbers*/

#include #include void main() { int a,b; clrscr(); printf("enter any two numbers"); scanf("%d%d",&a,&b); if(a>b) printf("a is large number:%d",a); else printf("b is large number:%d",b); getch(); } /*program to find out largest number in given three numbers*/ #include #include void main() { int a,b,c; clrscr(); printf("enter any three numbers"); scanf("%d%d%d",&a,&b,&c); if(a>b&&a>c) printf("a is large number:%d",a); else if(b>a&&b>c) printf("b is large number:%d",b); else printf("c is large number:%d",c); getch(); } /*program to do print the four digit number in the reverse form*/ #include #include void main() { int a,b,c,d,r1,r2,r3,r4; clrscr(); printf("enter the value of a four digit number"); scanf("%d",&a); r1=a%10; b=a/10; r2=b%10; c=b/10; r3=c%10; r4=c/10; d=r1*1000+r2*100+r3*10+r4*1; printf("reverse form=%d",d); getch(); }

/*program to find out the division*/ #include #include void main() { int a,b,c,d,e,av; clrscr(); printf("enter marks of five subjects"); scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); av=(a+b+c+d+e)/5; if(av>=60) printf("first division"); else if(av>=50&&av=35&&av
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF