SlideShare a Scribd company logo
C BASICS
                                 Program-1
//operators - eg of arithmetic operators.

 #include<stdio.h>
 #include<conio.h>
/*void main()
{
  int i,j,k;
  clrscr();
  printf("enter the i value:");
  scanf("%d",&i);
  printf("nthe value of i is:%d",i);
  printf("nenter the j value:");
  scanf("%d",&j);
  printf("nthe value ofj is:%d",j);
  k=i+j;
  printf("nsum of two numbers:%d",k);
  getch();
}
                                 Program-2
                                            */
//logicaloperators
 /*#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c;
   clrscr();
   printf("enter tha value of a:");
   scanf("%d",&a);
   printf("enter the value of b:");
   scanf("%d",&b);
   printf("enter the value of c:");
   scanf("%d",&c);
   if((a>b)&&(a>c))
   printf("a is greater");
   else if((b>a)&&(b>c))
   printf("b is greater");
   else
   printf("c is greater");
   getch();
}*

                                 Program-3

//relational oprators
/*#include<stdio.h>
#include<conio.h>
void main()
{
   int a;
   clrscr();
   printf("enter the value of a:");
   scanf("%d",&a);
   if(a%2==0)
   printf("given number is even");
   else
   printf("given number is odd");
   getch();
}*/


                                 Program-4

#include<stdio.h>
#include<conio.h>
void main()
{
  int a,b;
  clrscr();
  printf("enter the value of a:");
  scanf("%d",&a);
  printf("enter the value of b:");
  scanf("%d",&b);
// (a>b)?printf("%d",a):printf("%d",b);
(a>b)?printf("a is greater"):printf("b is greater");
  getch();
}
Program-5


#include<stdio.h>
#include<conio.h>
//#include"conio.h"
void main()
{
  char ch;
  clrscr();
  printf("enter a character:");
  scanf("%c",&ch);
  printf("%c",ch);
  printf("the ascii value is: %d",ch);
  getch();
}



                                  Program-6

#include<stdio.h>
#include<conio.h>
void main()
{
  int i;
  clrscr();
  for(i=1;i<=10;i++)
  {
    if(i==5)
      break;
    printf("%dn",i);
  }
  getch();
}
Program-7

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
//#include<process.h>
struct node
{
  int data;
  struct node *link;
};
void insert(struct node **p);
void del(struct node **p);
void disp(struct node *p);
void count(struct node *p);
void main()
{
   struct node *list;
   int choice;
   list=NULL;
   for(;;)
   {
     clrscr();
     printf("1Insertn2Deleten3Displayn4Countn5Exitn");
     printf("Enter your choice");
     scanf("%d",&choice);
     switch(choice)
     {
        case 1:
        insert(&list);
        break;

      case 2:
      del(&list);
      break;

      case 3:
      disp(list);
      break;

      case 4:
      count(list);
      break;

      case 5:
exit(0);
    }
  getch();
 }
}
void del(struct node **p)
{
  int d;
  struct node *temp,*ptr;
  printf("Enter the data to be deleted");
  scanf("%d",&d);
  if((*p)->data==d)
  {
     *p=(*p)->link;
     return;
  }
  temp=*p;
  ptr=temp;
  while(temp!=NULL)
  {
    if(temp->data==d)
    {
      ptr->link=temp->link;
      return;
    }
    ptr=temp;
    temp=temp->link;
  }
  if(temp==NULL)
  printf("%d nor foundn",d);
}
void disp(struct node *p)
{
  if(p==NULL)
  {
     printf("List Empty");
     return;
  }
  while(p!=NULL)
  {
    printf("n%d",p->data);
    p=p->link;
  }
}
void count(struct node *p)
{
int c=0;
 if(p==NULL)
 {
   printf("List emptyn");
   return;
 }
 while(p!=NULL)
 {
   c++;
   p=p->link;
 }
 printf("Count=%d",c);
}
void insert(struct node **p)
{
  struct node *temp,*ptr=NULL;
  ptr=malloc(sizeof(struct node));
  if(ptr==NULL)
  {
     printf("memory allocation unsuccessful");
     exit(0);
  }
  printf("enter the data:");
  scanf("%d",&ptr->data);
  ptr->link=NULL;
  if(*p==NULL)
  {
    *p=ptr;
  }
  else
  {
     temp=*p;
     while(temp->link!=NULL)
     temp=temp->link;
     temp->link=ptr;
  }
}
Program-8


#include<stdio.h>
#include<conio.h>
void main()
{
  int i;
  clrscr();
  for(i=1;i<=10;i++)
  {
    if(i==5)
      continue;
    printf("%dn",i);
  }
  getch();
}



                                   Program-9

#include<stdio.h>
#include<conio.h>
void main()
{
  int i=786;
  char ch='A';
  float f=3.14;
  double d=4000000000;
  clrscr();
  printf("integer value:%d",i);
  printf("ncharacter:%d",ch);
  printf("nfloat value:%f",f);
  printf("ndouble value:%e",d);
  getch();
}
Program-10

#include<stdio.h>
#include<conio.h>
void main()
{
  int i=1,n;             //give n=0
  clrscr();
  printf("enter the value:"); //result--print 1.
  scanf("%d",&n);
  do
  {
    printf("%dn",i);
    i=i+1;
  }while(i<=n);
  getch();
}
                                  Program-11

#include<stdio.h>
#include<conio.h>
void main()
{
  enum emp_dept
  {
    assembly,manufact,accounts,stores
  };
  struct employee
  {
    char name[30];
    int age;
    float bs;
    enum emp_dept department;
  };
  struct employee e;
  clrscr();
  strcpy(e.name,"jeevan");
  e.age=25;
  e.bs=5546.25;
  e.department=accounts;
  printf("name=%sn",e.name);
  printf("age=%dn",e.age);
printf("salary=%fn",e.bs);
    printf("dept=%dn",e.department);
    if(e.department==accounts)
    printf("%s is an acountants",e.name);
    else
    printf("%s is not an accountants",e.name);
    getch();
}



                                 Program-12

#include<stdio.h>
#include<conio.h>
void main()
{
float a;
clrscr();
scanf("%f",&a);
printf("%0.2f",a);
getch();
}


                                 Program-13


#include<stdio.h>
#include<conio.h>
void main()
  {
   int i;
   clrscr();
   for(i=1;i<=5;i++)
   {
         printf("%dn",i);
   }
// printf("n%*.*f",40,6,n);
   getch();
   }
Program-14

#include<stdio.h>
#include<conio.h>
void main()
{
 clrscr();
 printf("monday");
 printf("ntuesday");
 printf("nwednesday");
 printf("nsequence altered using goto");
 printf("nmonday");
 goto a;
 b:
 printf("ntuesday");
 goto end;
 a:
 printf("nwednesday");
 goto b;
 end:
 getch();
}


                               Program-15

#include<stdio.h>
void move(int,char,char,char);
void main()
{
  int n;
  clrscr();
  printf("towers of hanoi problem");
  printf("enter the number of discs:");
  scanf("%d",&n);
  move(n,'s','d','t');
  getch();
}
void move(int n,char source,char destination,char temp)
{
if(n>0)
    {
      move((n-1),source,temp,destination);
      printf("move disk#%d from %c to %cn",n,source,destination);
      move(n-1,temp,destination,source);
    }
}


                                 Program-16


#include<stdio.h>
#include<conio.h>
void main()
{
  void incre();
  void incre();
  clrscr();
  incre();
  incre();
  getch();
}
void incre()
{
  static int i=10;
  printf("%dn",i);
  i=i+1;
}




                                 Program-17
#include<stdio.h>
#include<conio.h>
void main()
{
  int a;
  clrscr();
  printf("enter the value of a:");
  scanf("%d",&a);
  switch(a)
  {
    case 1:
    printf("one");
break;

     case 2:
     printf("two");
     break;

     case 3:
     printf("three");
     break;

     case 4:
     printf("four");
     break;

     case 5:
     printf("five");
     break;

     default:
     printf("other numbers");
    }
    getch();
}



                                 Program-18

/*#include<stdio.h>
#include<conio.h>
main()
{
  char ch;
  clrscr();
  printf("enter the single character:");
  scanf("%c",&ch);
  switch(ch)
  {
    case 'a':
    case 'A':
    printf("Australia");
    break;

     case 'i':
     case 'I':
     printf("India");
break;

  case 'k':
  case 'K':
  printf("kenya");
  break;

  case 'l':
  case 'L':
  printf("London");
  break;

  default:
  printf("other countries");
 }
 getch();
} */

                                 Program-19

#include<stdio.h>
#include<conio.h>
void main()
{
  int i=1,n;        //give n=0
  clrscr();                //result--terminate the loop.
  printf("enter the value:");
  scanf("%d",&n);
  while(i<=n)
  {
    printf("%dn",i);
    i=i+1;
  }
  getch();
}

                                 Program-20

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  int c,d;
  clrscr();
c=fabs(23.9);
    d=sqrt(16);
    printf("c=%dn",c);
    printf("d=%d",d);
    getch();
}

                               Program-21
#include <stdio.h>
int i,j;
int a[5][5],b[5][5] ,d[5][5];
void create(flag,r,c)
int flag,r,c;
{
for (i=0;i<r;i++)
for (j=0;j<c;j++)
 if (flag==0)
 {
 printf(" n enter a[%d,%d]",i+1,j+1);
 scanf("%d",&a[i][j]);
 }
 else
 {
 printf("n enter b[%d,%d]",i+1,j+1);
 scanf("%d",&b[i][j]);
 }
 }
 void disp(a,r,c)
 int a[5][5],r,c;
 {
 for (i=0;i<r;i++)
 {
 for (j=0;j<c;j++)
 printf("%4d",a[i][j]);
 printf("n");
 }
 }
 void add(r,c)
 int r,c;
 {
 for(i=0;i<r;i++)
 for(j=0;j<c;j++)
 d[i][j]=a[i][j]+b[i][j];
 }
 void sub(r,c)
 int r,c;
{
for(i=0;i<r;i++)
for(j=0;j<c;j++)
d[i][j]=a[i][j]-b[i][j];
}
void mul(r,c,n)
int r,c,n;
{
int k;
for(i=0;i<r;i++)
for(j=0;j<n;j++)
{
d[i][j]=0;
 for(k=0;k<c;k++)
 d[i][j]+=a[i][k]*b[i][j];
 }
 }
 void trans(int r)
 {
 for(i=0;i<r;i++)
 for(j=0;j<r;j++)
 d[i][j]=a[i][j];
 }
 void main()
 {
 int r,c,m,n,ch;
 static flag=0;
 clrscr();
 printf("n enter the order of first matrix:");
 scanf("%d %d",&r,&c);
 create(flag,r,c);flag++;
 printf("n enter the order of second matrix;");
 scanf("%d %d",&m,&n);
 create(flag,m,n);
 do
 {
 getch(); clrscr();
 printf("n main menu");
 printf("n 1.addition");
 printf("n 2.subraction");
 printf("n 3.multipy");
 printf("n 4.transpose");
 printf("n 5.exit");
 printf("n enter your choice:");
 scanf("%d",&ch);
 if(ch==1 || ch==2 || ch==3)
{
printf("n first matrix:n");
 disp(a,r,c);
 printf("n second matrix:n");
 disp(b,n,m);
 }
 else
 {
 printf("n given matrox n");
 disp(a,r,c);
 }
 switch(ch)
 {
 case 1: if(r==m && c==n)
 {
 add(r,c);
 printf("n resultant matrix :n");
 disp(d,r,c);
 }
 else
 printf("n addition not possible");
 break;
 case 2: if(r==m && c==n)
 {
 sub(r,c);
 printf("n resultant matrix");
 disp(d,r,c);
 }
 else
 printf("n subraction is not possible");
 break;
 case 3: if(c==m)
 {
 mul(r,c,m);
 printf(" resultant matrix:n");
 disp(d,r,n);
 }
 else
 printf("n multiplication is not possible");
 break;
 case 4: if(r==c)
  {
  trans(r);
  printf("n resultant matrix: n");
  disp(d,r,c);
  }
else
  printf("n transpose not possible");
  break;
  }
  }
  while(ch!=5);
  }

                               Program-22

#include<stdio.h>
#include<conio.h>

void main()
{
register int a;
clrscr();
//a=1;
//scanf("%d",&a); //cannot get values from user,because register
                     // class values store to cpu register.cpu register
printf("%d",a); // didn't address.
}




                   DATA STRUCTURES
                                Program-1

#include<stdio.h>
#include<conio.h>
//#include<process.h>
#define MAX 10
#define TRUE 1
#define FALSE 0

struct que
{
  int rear,front;
  int items[MAX];
};
//void ins(struct que*,int);
//int overflow(struct que*);
//int empty(struct que*);
void insert(struct que*,int);
//int del(struct que*);
void display(struct que*);

int overflow(struct que *q)
{
  if(q->rear>MAX-1)
  return(1);
  else
  return(0);
}
int empty(struct que *q)
{
  if(q->rear<q->front)
  return(1);
  else
  return(0);
}


void main()
{
  int choice,x;
  struct que *q;
  clrscr();
  q->rear=-1;
  q->front=0;
  do
  {
 printf("n 1.insert n 2.deleten 3.displayn 4.exitn");
    printf("enter the choice:t");
    scanf("%d",&choice);
    switch(choice)
    {
         case 1:
         if(overflow(q))
         printf("n queue overflow");
         else
         {
        printf("n enter the element to be inserted:t");
        scanf("%d",&x);
        insert(q,x);
         }
         break;
case 2:
       if(empty(q))
       printf("n queue underflow");
       else
       printf("the delete element is %d",del(q));
       break;

       case 3:
       display(q);
       break;

  }
 }while(choice!=4);
}
void insert(struct que *q,int x)
{
/* if(overflow(q))
  {
         q->rear=-1;
         q->front=0;
         printf("queue overflow");
  }
  else*/
 q->items[++(q->rear)]=x;
}
int del(struct que *q)
{
/* if(empty(q))
   {
         printf(" queue underflow");
         return(1);
   }
   else */
   int m=q->items[q->front];
   q->front++;
   return(m);
}
void display(struct que *q)
{
  int i;
  if(empty(q))
  printf("queue empty");
  else
  for(i=q->front;i<=q->rear;i++)
  printf("n%d",q->items[i]);
}


                                 Program-2

#include<stdio.h>
#include<conio.h>
//#include<process.h>
#define MAX 10
#define TRUE 1
#define FALSE 0
struct stack
{
  int top;
  int items[MAX];
};
//int empty(struct stack*);
//int overflow(struct stack*);
void push(struct stack*,int);
//int pop(struct stack*);
void display(struct stack*);

int empty(struct stack *s)
{
  if(s->top==-1)
    return(1);
  else
    return(0);
}

int overflow(struct stack *s)
{
  if(s->top>=MAX-1)
    return(1);
  else
    return(0);
}

void main()
{
  int choice,x;
  struct stack *s;
  clrscr();
  s->top=-1;
  do
{
     printf("n 1.push n 2. pop n 3.displayn 4.exit n");
     printf("enter your choice:");
     scanf("%d",&choice);
     switch(choice)
     {
          case 1:
          if(overflow(s))
          printf("n stack overflow");
          else
          {
            printf("enter the element to be inserted:t");
            scanf("%d",&x);
            push(s,x);
          }
          break;

         case 2:
          if(empty(s))
          printf("n stack underflow");
          else
          printf("the popped element is%d",pop(s));
          break;

         case 3:
           display(s);
           break;

      /* case 4:
            printf("nEXIT");
          // exit(2); */
 }
 }
 while(choice!=4);
}

void push(struct stack *s,int x)
{
  s->items[++(s->top)]=x;
}

int pop(struct stack *s)
{
  int m;
  m=s->items[s->top];
  s->top--;
return(m);
}

void display(struct stack *s)
{
  int i;
  if(empty(s))
    printf("stack is empty");
  else
  {
    printf("display");
    for(i=s->top;i>=0;i--)
    printf("n%d",s->items[i]);
  }
}




                          FUNCTIONS
                                  Program-1


//no passing arg & no return type
#include<stdio.h>
#include<conio.h>
void main()
{     clrscr();

  printline();
  value();
  printline();
 getch();
}
 printline()
{
        int i;
        for (i=1;i<=35;i++)
        //printf("-");
        printf("%c",'-');
        printf("n");
}
value()
{
        int year,period;
        float inrate,sum,principal;
  printf("enter principle amount");
  scanf("%f",&principal);
  printf("nenter rate of interest:");
  scanf("%f",&inrate);
 printf("n enterperiod");
   scanf("%d",&period);
sum=principal;
year=1;
while(year<=period)
{
sum=sum*(1+inrate);
year=year+1;
}
printf("n%8.2f%5.2f%5d%12.2fn",principal,inrate,period,sum);
getch();
}

                               Program-2


//no passing arguments and return type.

#include<stdio.h>
#include<conio.h>
void main()
{
  int a,b,c;
  int fact();
  clrscr();
  a=fact()+5;
//a=fact();
  printf("a=%dn",a);
  b=fact()+10;
//b=fact();
  printf("b=%dn",b);
  c=fact()+15;
//c=fact();
  printf("c=%d",c);
  getch();
}
int fact()
{
    int i,n,f=1;
    printf("enter n:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
      f=f*i;
    }
    return f;
}
                               Program-3

#include<stdio.h>
#include<conio.h>
#include<dos.h>
 main()
 {
   static int marks[5]={40,90,73,81,2};
   int i;
   clrscr();
   printf("marks before sortingn");
   for(i=0;i<5;i++)
   printf("%d",marks[i]);
   printf("n");
   sort(5,marks);
   printf("marks after sorting");
   for(i=0;i<5;i++)
   printf("%4d",marks[i]);
   printf("n");
   getch();
 }
 sort(int m, int x[])
 {
        int i,j,t;
        for(i=1;i<=m-1;i++)
        for(j=1;j<=m-i;j++)
        if (x[j-1]>=x[j])
        {
                 t=x[j-1];
                 x[j-1]=x[j];
                 x[j]=t;
        }
 }
GRAPHICS
Ad

More Related Content

What's hot (19)

Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
C Programming
C ProgrammingC Programming
C Programming
Sumant Diwakar
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
C
CC
C
Mukund Trivedi
 
SaraPIC
SaraPICSaraPIC
SaraPIC
Sara Sahu
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
Hargun
HargunHargun
Hargun
Mukund Trivedi
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
vinay arora
 
programs
programsprograms
programs
Vishnu V
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
mohdshanu
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
ArghodeepPaul
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
Sushil Mishra
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
vinay arora
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
mohdshanu
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
ArghodeepPaul
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

Viewers also liked (8)

Superhero lunchwithouttitlepage
Superhero lunchwithouttitlepageSuperhero lunchwithouttitlepage
Superhero lunchwithouttitlepage
Jamie01010
 
01internet concepts
01internet concepts01internet concepts
01internet concepts
MSc CST
 
Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010
almataki
 
Materi Kup I Suwardi
Materi Kup I SuwardiMateri Kup I Suwardi
Materi Kup I Suwardi
Bayu Prasetyo
 
Internet application unit2
Internet application unit2Internet application unit2
Internet application unit2
MSc CST
 
Innovation As Project Management Pm Showcase SA 2007
Innovation As Project Management   Pm Showcase SA 2007Innovation As Project Management   Pm Showcase SA 2007
Innovation As Project Management Pm Showcase SA 2007
STARTPM
 
Superhero lunchwithouttitlepage
Superhero lunchwithouttitlepageSuperhero lunchwithouttitlepage
Superhero lunchwithouttitlepage
Jamie01010
 
01internet concepts
01internet concepts01internet concepts
01internet concepts
MSc CST
 
Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010
almataki
 
Materi Kup I Suwardi
Materi Kup I SuwardiMateri Kup I Suwardi
Materi Kup I Suwardi
Bayu Prasetyo
 
Internet application unit2
Internet application unit2Internet application unit2
Internet application unit2
MSc CST
 
Innovation As Project Management Pm Showcase SA 2007
Innovation As Project Management   Pm Showcase SA 2007Innovation As Project Management   Pm Showcase SA 2007
Innovation As Project Management Pm Showcase SA 2007
STARTPM
 
Ad

Similar to C basics (20)

'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
Ashishchinu
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C programming function
C  programming functionC  programming function
C programming function
argusacademy
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
Syed Tanveer
 
C file
C fileC file
C file
simarsimmygrewal
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
PRATHAMESH DESHPANDE
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
9096308941
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
ab11cs001
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65
 
C questions
C questionsC questions
C questions
mohamed sikander
 
Najmul
Najmul  Najmul
Najmul
Najmul Ashik
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
yogini sharma
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
loyola ICAM college of engineering and technology
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
Ad

Recently uploaded (20)

LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 

C basics

  • 1. C BASICS Program-1 //operators - eg of arithmetic operators. #include<stdio.h> #include<conio.h> /*void main() { int i,j,k; clrscr(); printf("enter the i value:"); scanf("%d",&i); printf("nthe value of i is:%d",i); printf("nenter the j value:"); scanf("%d",&j); printf("nthe value ofj is:%d",j); k=i+j; printf("nsum of two numbers:%d",k); getch(); } Program-2 */ //logicaloperators /*#include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("enter tha value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); printf("enter the value of c:"); scanf("%d",&c); if((a>b)&&(a>c)) printf("a is greater"); else if((b>a)&&(b>c)) printf("b is greater"); else printf("c is greater"); getch();
  • 2. }* Program-3 //relational oprators /*#include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter the value of a:"); scanf("%d",&a); if(a%2==0) printf("given number is even"); else printf("given number is odd"); getch(); }*/ Program-4 #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); // (a>b)?printf("%d",a):printf("%d",b); (a>b)?printf("a is greater"):printf("b is greater"); getch(); }
  • 3. Program-5 #include<stdio.h> #include<conio.h> //#include"conio.h" void main() { char ch; clrscr(); printf("enter a character:"); scanf("%c",&ch); printf("%c",ch); printf("the ascii value is: %d",ch); getch(); } Program-6 #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for(i=1;i<=10;i++) { if(i==5) break; printf("%dn",i); } getch(); }
  • 4. Program-7 #include<stdio.h> #include<conio.h> #include<alloc.h> //#include<process.h> struct node { int data; struct node *link; }; void insert(struct node **p); void del(struct node **p); void disp(struct node *p); void count(struct node *p); void main() { struct node *list; int choice; list=NULL; for(;;) { clrscr(); printf("1Insertn2Deleten3Displayn4Countn5Exitn"); printf("Enter your choice"); scanf("%d",&choice); switch(choice) { case 1: insert(&list); break; case 2: del(&list); break; case 3: disp(list); break; case 4: count(list); break; case 5:
  • 5. exit(0); } getch(); } } void del(struct node **p) { int d; struct node *temp,*ptr; printf("Enter the data to be deleted"); scanf("%d",&d); if((*p)->data==d) { *p=(*p)->link; return; } temp=*p; ptr=temp; while(temp!=NULL) { if(temp->data==d) { ptr->link=temp->link; return; } ptr=temp; temp=temp->link; } if(temp==NULL) printf("%d nor foundn",d); } void disp(struct node *p) { if(p==NULL) { printf("List Empty"); return; } while(p!=NULL) { printf("n%d",p->data); p=p->link; } } void count(struct node *p) {
  • 6. int c=0; if(p==NULL) { printf("List emptyn"); return; } while(p!=NULL) { c++; p=p->link; } printf("Count=%d",c); } void insert(struct node **p) { struct node *temp,*ptr=NULL; ptr=malloc(sizeof(struct node)); if(ptr==NULL) { printf("memory allocation unsuccessful"); exit(0); } printf("enter the data:"); scanf("%d",&ptr->data); ptr->link=NULL; if(*p==NULL) { *p=ptr; } else { temp=*p; while(temp->link!=NULL) temp=temp->link; temp->link=ptr; } }
  • 7. Program-8 #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for(i=1;i<=10;i++) { if(i==5) continue; printf("%dn",i); } getch(); } Program-9 #include<stdio.h> #include<conio.h> void main() { int i=786; char ch='A'; float f=3.14; double d=4000000000; clrscr(); printf("integer value:%d",i); printf("ncharacter:%d",ch); printf("nfloat value:%f",f); printf("ndouble value:%e",d); getch(); }
  • 8. Program-10 #include<stdio.h> #include<conio.h> void main() { int i=1,n; //give n=0 clrscr(); printf("enter the value:"); //result--print 1. scanf("%d",&n); do { printf("%dn",i); i=i+1; }while(i<=n); getch(); } Program-11 #include<stdio.h> #include<conio.h> void main() { enum emp_dept { assembly,manufact,accounts,stores }; struct employee { char name[30]; int age; float bs; enum emp_dept department; }; struct employee e; clrscr(); strcpy(e.name,"jeevan"); e.age=25; e.bs=5546.25; e.department=accounts; printf("name=%sn",e.name); printf("age=%dn",e.age);
  • 9. printf("salary=%fn",e.bs); printf("dept=%dn",e.department); if(e.department==accounts) printf("%s is an acountants",e.name); else printf("%s is not an accountants",e.name); getch(); } Program-12 #include<stdio.h> #include<conio.h> void main() { float a; clrscr(); scanf("%f",&a); printf("%0.2f",a); getch(); } Program-13 #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); for(i=1;i<=5;i++) { printf("%dn",i); } // printf("n%*.*f",40,6,n); getch(); }
  • 10. Program-14 #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("monday"); printf("ntuesday"); printf("nwednesday"); printf("nsequence altered using goto"); printf("nmonday"); goto a; b: printf("ntuesday"); goto end; a: printf("nwednesday"); goto b; end: getch(); } Program-15 #include<stdio.h> void move(int,char,char,char); void main() { int n; clrscr(); printf("towers of hanoi problem"); printf("enter the number of discs:"); scanf("%d",&n); move(n,'s','d','t'); getch(); } void move(int n,char source,char destination,char temp) {
  • 11. if(n>0) { move((n-1),source,temp,destination); printf("move disk#%d from %c to %cn",n,source,destination); move(n-1,temp,destination,source); } } Program-16 #include<stdio.h> #include<conio.h> void main() { void incre(); void incre(); clrscr(); incre(); incre(); getch(); } void incre() { static int i=10; printf("%dn",i); i=i+1; } Program-17 #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter the value of a:"); scanf("%d",&a); switch(a) { case 1: printf("one");
  • 12. break; case 2: printf("two"); break; case 3: printf("three"); break; case 4: printf("four"); break; case 5: printf("five"); break; default: printf("other numbers"); } getch(); } Program-18 /*#include<stdio.h> #include<conio.h> main() { char ch; clrscr(); printf("enter the single character:"); scanf("%c",&ch); switch(ch) { case 'a': case 'A': printf("Australia"); break; case 'i': case 'I': printf("India");
  • 13. break; case 'k': case 'K': printf("kenya"); break; case 'l': case 'L': printf("London"); break; default: printf("other countries"); } getch(); } */ Program-19 #include<stdio.h> #include<conio.h> void main() { int i=1,n; //give n=0 clrscr(); //result--terminate the loop. printf("enter the value:"); scanf("%d",&n); while(i<=n) { printf("%dn",i); i=i+1; } getch(); } Program-20 #include<stdio.h> #include<conio.h> #include<math.h> void main() { int c,d; clrscr();
  • 14. c=fabs(23.9); d=sqrt(16); printf("c=%dn",c); printf("d=%d",d); getch(); } Program-21 #include <stdio.h> int i,j; int a[5][5],b[5][5] ,d[5][5]; void create(flag,r,c) int flag,r,c; { for (i=0;i<r;i++) for (j=0;j<c;j++) if (flag==0) { printf(" n enter a[%d,%d]",i+1,j+1); scanf("%d",&a[i][j]); } else { printf("n enter b[%d,%d]",i+1,j+1); scanf("%d",&b[i][j]); } } void disp(a,r,c) int a[5][5],r,c; { for (i=0;i<r;i++) { for (j=0;j<c;j++) printf("%4d",a[i][j]); printf("n"); } } void add(r,c) int r,c; { for(i=0;i<r;i++) for(j=0;j<c;j++) d[i][j]=a[i][j]+b[i][j]; } void sub(r,c) int r,c;
  • 15. { for(i=0;i<r;i++) for(j=0;j<c;j++) d[i][j]=a[i][j]-b[i][j]; } void mul(r,c,n) int r,c,n; { int k; for(i=0;i<r;i++) for(j=0;j<n;j++) { d[i][j]=0; for(k=0;k<c;k++) d[i][j]+=a[i][k]*b[i][j]; } } void trans(int r) { for(i=0;i<r;i++) for(j=0;j<r;j++) d[i][j]=a[i][j]; } void main() { int r,c,m,n,ch; static flag=0; clrscr(); printf("n enter the order of first matrix:"); scanf("%d %d",&r,&c); create(flag,r,c);flag++; printf("n enter the order of second matrix;"); scanf("%d %d",&m,&n); create(flag,m,n); do { getch(); clrscr(); printf("n main menu"); printf("n 1.addition"); printf("n 2.subraction"); printf("n 3.multipy"); printf("n 4.transpose"); printf("n 5.exit"); printf("n enter your choice:"); scanf("%d",&ch); if(ch==1 || ch==2 || ch==3)
  • 16. { printf("n first matrix:n"); disp(a,r,c); printf("n second matrix:n"); disp(b,n,m); } else { printf("n given matrox n"); disp(a,r,c); } switch(ch) { case 1: if(r==m && c==n) { add(r,c); printf("n resultant matrix :n"); disp(d,r,c); } else printf("n addition not possible"); break; case 2: if(r==m && c==n) { sub(r,c); printf("n resultant matrix"); disp(d,r,c); } else printf("n subraction is not possible"); break; case 3: if(c==m) { mul(r,c,m); printf(" resultant matrix:n"); disp(d,r,n); } else printf("n multiplication is not possible"); break; case 4: if(r==c) { trans(r); printf("n resultant matrix: n"); disp(d,r,c); }
  • 17. else printf("n transpose not possible"); break; } } while(ch!=5); } Program-22 #include<stdio.h> #include<conio.h> void main() { register int a; clrscr(); //a=1; //scanf("%d",&a); //cannot get values from user,because register // class values store to cpu register.cpu register printf("%d",a); // didn't address. } DATA STRUCTURES Program-1 #include<stdio.h> #include<conio.h> //#include<process.h> #define MAX 10 #define TRUE 1 #define FALSE 0 struct que { int rear,front; int items[MAX]; }; //void ins(struct que*,int);
  • 18. //int overflow(struct que*); //int empty(struct que*); void insert(struct que*,int); //int del(struct que*); void display(struct que*); int overflow(struct que *q) { if(q->rear>MAX-1) return(1); else return(0); } int empty(struct que *q) { if(q->rear<q->front) return(1); else return(0); } void main() { int choice,x; struct que *q; clrscr(); q->rear=-1; q->front=0; do { printf("n 1.insert n 2.deleten 3.displayn 4.exitn"); printf("enter the choice:t"); scanf("%d",&choice); switch(choice) { case 1: if(overflow(q)) printf("n queue overflow"); else { printf("n enter the element to be inserted:t"); scanf("%d",&x); insert(q,x); } break;
  • 19. case 2: if(empty(q)) printf("n queue underflow"); else printf("the delete element is %d",del(q)); break; case 3: display(q); break; } }while(choice!=4); } void insert(struct que *q,int x) { /* if(overflow(q)) { q->rear=-1; q->front=0; printf("queue overflow"); } else*/ q->items[++(q->rear)]=x; } int del(struct que *q) { /* if(empty(q)) { printf(" queue underflow"); return(1); } else */ int m=q->items[q->front]; q->front++; return(m); } void display(struct que *q) { int i; if(empty(q)) printf("queue empty"); else for(i=q->front;i<=q->rear;i++) printf("n%d",q->items[i]);
  • 20. } Program-2 #include<stdio.h> #include<conio.h> //#include<process.h> #define MAX 10 #define TRUE 1 #define FALSE 0 struct stack { int top; int items[MAX]; }; //int empty(struct stack*); //int overflow(struct stack*); void push(struct stack*,int); //int pop(struct stack*); void display(struct stack*); int empty(struct stack *s) { if(s->top==-1) return(1); else return(0); } int overflow(struct stack *s) { if(s->top>=MAX-1) return(1); else return(0); } void main() { int choice,x; struct stack *s; clrscr(); s->top=-1; do
  • 21. { printf("n 1.push n 2. pop n 3.displayn 4.exit n"); printf("enter your choice:"); scanf("%d",&choice); switch(choice) { case 1: if(overflow(s)) printf("n stack overflow"); else { printf("enter the element to be inserted:t"); scanf("%d",&x); push(s,x); } break; case 2: if(empty(s)) printf("n stack underflow"); else printf("the popped element is%d",pop(s)); break; case 3: display(s); break; /* case 4: printf("nEXIT"); // exit(2); */ } } while(choice!=4); } void push(struct stack *s,int x) { s->items[++(s->top)]=x; } int pop(struct stack *s) { int m; m=s->items[s->top]; s->top--;
  • 22. return(m); } void display(struct stack *s) { int i; if(empty(s)) printf("stack is empty"); else { printf("display"); for(i=s->top;i>=0;i--) printf("n%d",s->items[i]); } } FUNCTIONS Program-1 //no passing arg & no return type #include<stdio.h> #include<conio.h> void main() { clrscr(); printline(); value(); printline(); getch(); } printline() { int i; for (i=1;i<=35;i++) //printf("-"); printf("%c",'-'); printf("n"); }
  • 23. value() { int year,period; float inrate,sum,principal; printf("enter principle amount"); scanf("%f",&principal); printf("nenter rate of interest:"); scanf("%f",&inrate); printf("n enterperiod"); scanf("%d",&period); sum=principal; year=1; while(year<=period) { sum=sum*(1+inrate); year=year+1; } printf("n%8.2f%5.2f%5d%12.2fn",principal,inrate,period,sum); getch(); } Program-2 //no passing arguments and return type. #include<stdio.h> #include<conio.h> void main() { int a,b,c; int fact(); clrscr(); a=fact()+5; //a=fact(); printf("a=%dn",a); b=fact()+10; //b=fact(); printf("b=%dn",b); c=fact()+15; //c=fact(); printf("c=%d",c); getch(); } int fact()
  • 24. { int i,n,f=1; printf("enter n:"); scanf("%d",&n); for(i=1;i<=n;i++) { f=f*i; } return f; } Program-3 #include<stdio.h> #include<conio.h> #include<dos.h> main() { static int marks[5]={40,90,73,81,2}; int i; clrscr(); printf("marks before sortingn"); for(i=0;i<5;i++) printf("%d",marks[i]); printf("n"); sort(5,marks); printf("marks after sorting"); for(i=0;i<5;i++) printf("%4d",marks[i]); printf("n"); getch(); } sort(int m, int x[]) { int i,j,t; for(i=1;i<=m-1;i++) for(j=1;j<=m-i;j++) if (x[j-1]>=x[j]) { t=x[j-1]; x[j-1]=x[j]; x[j]=t; } }