• No results found

Language c Basics

N/A
N/A
Protected

Academic year: 2021

Share "Language c Basics"

Copied!
5
0
0

Loading.... (view fulltext now)

Full text

(1)

‘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) An integer constant must have at least one digit.

b) It must not have a decimal point.

c) It could be either positive or negative.

d) No commas or blanks are allowed within an integer constant.

e) The allowable range for integer constants is -32768 to +32767.

Rules for Constructing Real Constants

a) An integer constant must have at least one digit.

b) It must have a decimal point.

c) It could be either positive or negative.

d) 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.

(2)

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

double

if

static

break

else

int

struct

case

enum

long

switch

char

extern

near

typedef

const

float

register

union

continue

return

default

for

(3)

/*for simple addition, subtraction, multiplication and division*/

#include<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> #include<math.h> 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<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> 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(); }

(4)

/*program to find out the division*/ #include<stdio.h> #include<conio.h> 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<60) printf("second division"); else if(av>=35&&av<50) printf("third division"); else printf("fail"); getch(); }

/*programe to do print the counting*/

#include<stdio.h> #include<conio.h> void main() { int counting=1; clrscr(); while(counting<=100) { printf("%d\t",counting); counting=counting+1; } }

/*programe to find out the value of even numbers among 1 to 100*/ #include<stdio.h> #include<conio.h> void main() { int count=1,even=0; clrscr(); while(count<=100) { if(count%2==0) { printf("%d\t",count); even=even+1; } count=count+1; } }

/*find the enter number is prine or not*/

#include<stdio.h> #include<conio.h> void main() { int num,i; clrscr();

printf("\n enter a numner"); scanf("%d",&num); i=2; while(i<num) { if(num%i==0) {

printf("not a prime number"); break; } i++; } if(i==num) printf("prime number"); getch(); }

/*program for printing ‘*’ */

#include<stdio.h> #include<conio.h> void main() { int rows,i,j; clrscr();

printf("\n enter the number of rows:"); scanf("%d",&rows); for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) printf("*"); printf("\n"); } }

/*magic number program*/

#include<stdio.h> #include<conio.h> void main() { int magic=22; int guess; clrscr();

printf("enter your guess for the number"); scanf("%d",&guess);

if(guess==magic)

printf("\n Congratulation!Right guess"); else

(5)

getch(); }

/*find wheather number is even or odd by using switch case*/

#include<stdio.h> #include<conio.h> void main() {

int n,ch;

printf("Enter the number:\n"); scanf("%d",&n); if(n%2==0) ch=1; else ch=2; switch(ch) { case 1: printf("number is even\n"); break; case 2: printf("number is odd\n"); } }

/*Find the sum of the number*/

#include<stdio.h> #include<conio.h> void main() { int num,count,sum,rem; clrscr(); sum=0;

printf("Enter the number"); scanf("%d",&num); for(count=num;count>0;count/=10) { rem=count%10; sum+=rem; } printf("sum of digit=%d",sum); getch(); }

/*progame to find average of a set of numbers*/ #include<stdio.h> #include<conio.h> void main() { int n,count=0; float x,average,sum=0; clrscr();

printf("how many numbers");

scanf("%d",&n); while(count<n) { printf("\n %d number=",count+1); scanf("%f",&x); sum+=x; ++count; } average=sum/n;

printf("\n average is %f",average); getch(); } void main() { int x; printf("enter a number"); scanf("%d",&x); while(x<=100) { if(x<0) {

printf("enter nagative value for x"); break;

}

/*pocess for non negative number*/ scanf("%d",&x); } } #include<stdio.h> void main() { int i; for(i=1;i<=5;i++) stat(); } stat() { static int x=0; x=x+1; printf("x=%d\t",x); }

References

Related documents

Exports a data, where are scheduled tasks stored procedure is kept in the stored credential manager control the week field because of tasks are logged in the agents.. Version of

Here are some examples that define macros for swapping numbers, an ordinary label whose scope is the whole function cannot be used: if the macro can be expanded several times in

Ionization detector when installed and photoelectric smoke alarms shall be used to your browser as an integral safety and research, test detectors required upon successful

Keyword extern is used to declaring a global variable or function in another file to sour the reference of variable or function which was been.. The site for readers of declaring

If you wish your wife not to conceive as yet, simply inscribe the verse below on a virgin piece of parchment, fold it, put it in a pouch and have your wife wear it as a pendant..

o Where the message element specified in the ISO 20022 XML standard is used for SEPA core payments without change (regarding its mandatory or optional status, number

These faults have been applied to the pneumatic system and the results show that using the described parity equation and Kalman filter methods; including the

Once an account is placed with an outside collection agency, an inquiring student should be referred by Pace staff to the Pace internal collections office