SlideShare a Scribd company logo
1 of 25
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

More Related Content

What's hot

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
 
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
 
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
 

What's hot (20)

Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
C Programming
C ProgrammingC Programming
C Programming
 
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
 
C
CC
C
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Double linked list
Double linked listDouble linked list
Double linked list
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
Hargun
HargunHargun
Hargun
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
programs
programsprograms
programs
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
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
 
C lab programs
C lab programsC lab programs
C lab programs
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan 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
 

Viewers also liked (8)

Superhero lunchwithouttitlepage
Superhero lunchwithouttitlepageSuperhero lunchwithouttitlepage
Superhero lunchwithouttitlepage
 
01internet concepts
01internet concepts01internet concepts
01internet concepts
 
Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010Alma.Daskalaki.Portfolio 2010
Alma.Daskalaki.Portfolio 2010
 
Materi Kup I Suwardi
Materi Kup I SuwardiMateri Kup I Suwardi
Materi Kup I Suwardi
 
Uisvr1.5
Uisvr1.5Uisvr1.5
Uisvr1.5
 
Materi Kup Ii By
Materi Kup Ii ByMateri Kup Ii By
Materi Kup Ii By
 
Internet application unit2
Internet application unit2Internet application unit2
Internet application unit2
 
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
 

Similar to C basics

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 

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)
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
C programming function
C  programming functionC  programming function
C programming function
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
C file
C fileC file
C file
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
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
 
C lab programs
C lab programsC lab programs
C lab programs
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
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
 
C questions
C questionsC questions
C questions
 
Najmul
Najmul  Najmul
Najmul
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
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
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
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
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
7 functions
7  functions7  functions
7 functions
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

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; } }