Data structure and c
description
Transcript of Data structure and c
Introduction in c
• C program made by ken Thompson and Dennis Ritchie
in 1970.
• Developed by martin Richards.
• Although C was designed for implementing System
Software.
• It is also widely used for developing portable
Application Software.
Means
• C program mean compiler programming
• C is a Program language.
• It is a middle level language
• This programming language is designed to help as Data
process.
• Data process is numbers, characters and strings.
• Its provide use of output display
The Character Set in C
1) Upper case alphabets:
• It is capital word alphabets
Example:• A B C D E …….Z
Sample code Program
#include<stdio.h>power(int*m,int*n);void main(){ int X,Y;clrscr();printf("Enter number:");scanf("%d",&X);
fflush(stdin);printf("Enter power to raise to:");scanf("%d",&Y);fflush(stdin);power(&X,&Y); ……………..……………………………….getch();
2) Lower case alphabets:
•It is small word through called by lower case alphabets
Example:
• a b c d e……..z
Sample Code Program#include<stdio.h>power(int*m,int*n);void main(){ int x,y;clrscr();printf("Enter number:");scanf("%d",&x);
• fflush(stdin);• printf("Enter power to
raise to:");• scanf("%d",&y);• fflush(stdin);• power(&x,&y);• ……………..• ………………• ……………….• getch();• }
3) Numbered or digital characters:
•It means also used by number or Ditital characters.
Example:
• 0 1 2 3 4 5 6 7 8 9
Sample code Program#include<stdio.h>void main(){int a,b;char cmd[25];……….
……….
……….}
#include<stdio.h>#include<conio.h>void main(){char name[21],addrs[31];clrscr();puts("Enter your Name to a maximum of 20 characters");puts("Enter your Address to a maximum of 30 characters");…………}
4) Arithmetic Operators:
•It means arithmetic program through operated by arithmetic operators.
•Example:
• + , %, *, - •Plus,Division,Multiple and Minus
Sample Code Program#include<stdio.h>sum(int a,int b);void main(){int x,y,value;scanf("%d%d",&x,&y);value=sum(x,y);printf("Total is %d\n",value);}sum(int a,int b){return a+b;}
OUTPUT
Output::53
Total is 8
5) Relational Operators:
•It is numberic and case character relation operated by relational operators.
•Syntax:-
•< >, < = >, = , =•Less and Great, Less Equal Great,Equal•Example•Example:• 4>5,6<4,4=4
Sample Code Program
#include<stdio.h>
#include<conio.h>
void main()
{
int I,sum,num;
clrscr();
sum=num=0;
for(I=0;I<8;I=I+1)
{
……..
……..
……..if(num<=0)getch();}
• 6) curly brace:Syntax:- { }
• { → Starting curely space• } → Ending curely space• Example:• {……………………}
Sample Code Program
{ Head of curly…………..…………..…………..{ Sub of curly…………..…………..
} Sub End of curly……….……….getch();} Head End of Curly
Sample Code program#include<stdio.h>#include<conio.h>void main(){char str1[101],str2[101];int diff,I=0;clrscr();………..………..getch();}
Sample Code program
Program::#include<stdio.h>#include<conio.h>void main(){char in_str[21];clrscr();
puts("Enter a string to a maximum of 20 characters");gets(in_str);fflush(stdin);puts(in_str);getch();}
• 9) Special characters:
• It mean other syntax characters
Syntax:-• &, !, #, ?, ~, `, @, ^, $, |,:,; .
Sample code program#include<stdio.h>#include<conio.h>void main(){char yn;clrscr();do{ puts("enter y/n(yes/no)");yn=getchar();fflush(stdin);if(yn!='y'&&yn!='n')puts("invalid input");}while(yn!='y'&&yn!='n'); getch();}