some defult programs

                   c programming practice programs 

  /Program to check whether character is vowel or not
#include<stdio.h>
void main()
{
 char ch;
 printf("Enter a character\n");
 scanf("%c",&ch);
 switch(ch)
 {
  case 'A':
  case 'a':
  case 'E':
  case 'e':
  case 'I':
  case 'i':
  case 'O':
  case 'o':
  case 'U':
  case 'u':printf("Entered character is a vowel\n");
    break;
  default: printf("Entered character is not a vowel\n");
 }
}

#include<stdio.h>
#define r 3
#define c 3
void main()
{
        int a[r][c],b[c][r];
        int i,j;
        printf("Enter matrix a\n");
        for(i=0;i<r;i++)
        {
                for(j=0;j<c;j++)
                        scanf("%d",&a[i][j]);
        }
        for(i=0;i<c;i++)
        {
                for(j=0;j<r;j++)
                {
                       b[i][j]=a[j][i];
                }
        }
        printf("\nThe transpose of the matrix is:\n");
        for(i=0;i<c;i++)
        {
                for(j=0;j<r;j++)
                {
                        printf("%d\t",b[i][j]);
                }
                printf("\n");
        }
}


#include<stdio.h>
void main()
{
 int num;
 printf("Enter a number \n");
 scanf("%d",&num);
 int pos,n,i;
 printf("Which bit u want to toggle\n");
 scanf("%d",&pos);
 printf("Before toggling ");
 for(i=7;i>=0;i--)
 {
  if((num & (1<<i))==0)
   printf("0");
  else
   printf("1");
 }
 printf("\nAfter toggling ");

 n = num ^ (1<<pos);
 for(i=7;i>=0;i--)
        {
                if((n & (1<<i))==0)
                        printf("0");
                else
                        printf("1");
        }


}



#include<stdio.h>
#define swap(a,b) temp=a; a=b; b=temp;
void main()
{
 int a=5,b=6,temp;
 printf("Before swapping,a=%d,b=%d",a,b);
 swap(a,b);
 printf("\nAfter swapping,a=%d,b=%d",a,b) ;
}
#include<stdio.h>
void main()
{
 int a,b;
 printf("Enter two numbers\n");
 scanf("%d %d",&a,&b);
 printf("Before swapping a=%d b=%d\n",a,b);
 a = a ^ b;
 b = a ^ b;
 a = a ^ b;
 printf("After swapping a=%d b=%d",a,b);
}
#include<stdio.h>
void main()
{
 int a,b;
 printf("Enter values of a and b\n");
 scanf("%d %d",&a,&b);
 printf("Values of a  before swapping, a=%d,b=%d\n",a,b);
 a=b-a;
 b=b-a;
 a=a+b;
 printf("Values of a  after  swapping, a=%d,b=%d\n",a,b);
}
//Program to find sum of digits of a number
#include<stdio.h>
void main()
{
 int num=123,sum=0,digit;
 while(num>0)
 {
  digit = num % 10;
  sum += digit;
  num /= 10;
 }
 printf("The sum of digits is: %d\n",sum);
}
  
#include<stdio.h>
int str_len(char ch[])
{
 int i;
 for(i=0;ch[i]!='\0';i++);
 return i;
}
void main()
{
 char str[]="Cranes";
 int len = str_len(str);
 printf("Length of string is %d",len);
}
#include<stdio.h>
void str_cpy(char des[],char src[])
{
 int i;
 for(i=0;src[i]!='\0';i++)
 {
  des[i]=src[i];
 }
 des[i]='\0';
 printf("After copying we have %s",des);
}
void main()
{
 char src[]="cranes";
 char des[10];
 str_cpy(des,src);
}
#include<stdio.h>
int str_cmp(char str[],char str2[])
{
        int i;
        for(i=0;str[i]!='\0'|| str2[i]!='\0';i++)
        {
  if(str[i]!=str2[i])
   return (str[i]-str2[i]);

        }
 return 0;
    

}




void main()
{
        char str[]="Cranes";
        char str2[]="Cranes ";
        int val=str_cmp(str,str2);
 if(val == 0)
  printf("both are same");
 else if(val > 0)
  printf("str1 is greater");
 else
  printf("str2 is greater");
}


#include<stdio.h>
void str_cat(char des[],char src[])
{
        int i,j;
        for(i=0;des[i]!='\0';i++);
        for(j=0;src[j]!='\0';j++,i++)
        {
                des[i]=src[j];
        }
        des[i]='\0';
        printf("After concatenating we have %s",des);
}
void main()
{
        char src[]="varsity";
        char des[]="cranes";
        str_cat(des,src);
}


#include<string.h>
void main()
{
 char ch[10];
 printf("Enter the string\n");
// scanf("%s",ch); // ll not scan space
//      gets(ch); // ll not check memory
 fgets(ch,10,stdin);
 printf("%s",ch);
 printf("\n%d",strlen(ch));
 printf("\n%d",strlen("cranes"));
 printf("\n%d",sizeof("cranes"));
 printf("\n%d",sizeof(ch));
}

#include<stdio.h>
void fun()
{
 static int a=10;
 a++;
 printf("%d\n",a);
}
void main()
{
 static int b;
 printf("%d\n",b);
 fun();
 fun();
 fun();
}

//Function to find sum of digits of a number
#include<stdio.h>
int sumd(int);
void main()
{
 int n;
 printf("Enter a number\n");
 scanf("%d",&n);
 int s= sumd(n);
 printf("Sum of  digits of the number is %d\n",s);
}
int sumd(int num)
{
 int sum=0, digit;
 while(num>0)
 {
  digit= num%10;
  sum+=digit;
  num/=10;
 }
 return sum;
}

#include<stdio.h>
void main()
{
 printf("\n%d\n",sizeof(int));
 printf("%d\n",sizeof(char));
 printf("%d\n",sizeof(float));
 printf("%d\n",sizeof(double));
}

#include<stdio.h>
void main()
{
 int a;
 char ch;
 float f;
 double d;
 printf("Enter value of a,ch,f,d\n");
 scanf(" %d",&a);
 scanf(" %c",&ch);
 scanf(" %f",&f);
 scanf(" %lf",&d);
 printf("Value of a= %d\n",a);
 printf("The value of ch=%c\n",ch);
 printf("The value of f=%f\n",f);
 printf("The value of d=%lf\n",d);

}

#include<stdio.h>
void main()
{
 char a;
 int pos,i;
 printf("Enter a number\n");
 scanf("%c",&a);
 printf("Enter the bit position\n");
 scanf("%d",&pos);
 for(i=7;i>=0;i--)
 {
  if((a & (1<<i))==0)
   printf("0 ");
  else
   printf("1 ");
 }
// a = a | (1<<pos); //set a bit
// a = a & ~(1<<pos); //clear a bit
 a = a ^ (1<<pos); //toggle a bit
 printf("\nAfter setting\n");
 for(i=7;i>=0;i--)
        {
                if((a & (1<<i))==0)
                        printf("0 ");
                else
                        printf("1 ");
        }

}

#include<stdio.h>
#define r 3
#define c 2
void main()
{
        int a[r][c];
        int i,j;
        printf("Enter matrix a\n");
        for(i=0;i<r;i++)
        {
                for(j=0;j<c;j++)
                        scanf("%d",&a[i][j]);
        }
  /*      for(i=0;i<c;i++)
        {
                for(j=0;j<r;j++)
                {
                       b[i][j]=a[j][i];
                }
        }*/
        printf("\nrotating the matrix 90 degree clockwise:\n");
        for(i=0;i<c;i++)
        {
                for(j=r-1;j>=0;j--)
                {
                        printf("%d\t",a[j][i]);
                }
                printf("\n");
        }
}


#include<stdio.h>
#define r 3
#define c 3
void main()
{
        int a[r][c],b[c][r];
        int i,j;
        printf("Enter matrix a\n");
        for(i=0;i<r;i++)
        {
                for(j=0;j<c;j++)
                        scanf("%d",&a[i][j]);
        }
  /*      for(i=0;i<c;i++)
        {
                for(j=0;j<r;j++)
                {
                       b[i][j]=a[j][i];
                }
    }*/
        printf("\nrotating the matrix 90 degree anticlockwise:\n");
        for(i=c-1;i>=0;i--)
        {
                for(j=0;j<r;j++)
                {
                        printf("%d\t",a[j][i]);
                }
                printf("\n");
        }
}



#include<stdio.h>
#include<string.h>
void main()
{
 int i,j;
 char str[]="cranes varsity";
 for(i=0,j=strlen(str)-1;i<j;i++,j--)
 {
  char temp=str[i];
  str[i]=str[j];
  str[j]=temp;
 }
 printf("The reversed string is : %s",str);

}

// Program to print prime nos from 1 to 100 using function
#include<stdio.h>
int prime(int);
void main()
{
 int i;
 for(i=1;i<=100;i++)
 {
  if(prime(i))
   printf("%d ",i);
 }
}
int prime(int n)
{
 int i,c=0;
 for(i=2;i<=n/2;i++)
 {
  if(n%i==0)
  {
   c=1;
   break;
  }
 }
 if(c==0)
  return 1;
 else
  return 0;
}
#include<stdio.h>
void main()
{
 int i,j,c=0;
 printf("The prime nos from 1 to 100 are :");

 for(i=1;i<=100;i++)
 {
  c=0;
  for(j=2;j<=i/2;j++)
  {
   if(i%j==0)
    c++;
  }
  if(c==0)
   printf("%d ",i);
 }
}
//program to find if no. is primeor not
#include<stdio.h>
void main()
{
 int num,i,c=0;
 printf("Enter a number\n");
 scanf("%d",&num);
 for(i=2;i<=num/2;i++)
 {
  if(num % i==0)
   c++;
 }
 if(c==0)
  printf("Prime");
 else
  printf("Not prime");
}

#include<stdio.h>
#define max 5
#define print printf("\nHello");
#define val "\ncranes"
#define MAIN main
#define prin printf("\nHii \
   Hello\
   World");
#define add(a,b) a+b
#define mul(a,b) a*b
int MAIN()
{
 //sample code
 printf("%d",max);
 print
 printf(val);
 prin
 printf("\nRes = %d", add(5,6));
 printf("\nProd = %d", mul(2+3,3+2));
}

#include<stdio.h>
void main()
{
 int num,flag=0;
 printf("Enter a number\n");
 scanf("%d",&num);
 while(num>1)
 {
  if(num%4!=0)
  {
   flag =1;
   break;
  }
  num = num /4;

 }
 if(flag==0)
  printf("Power of 4");
 else
  printf("Not power of 4");

}
 
#include<stdio.h>
void main()
{
        int i,j,k;
        for(i=1;i<=4;i++)
        {
                for(k=4;k>i;k--)
                        printf(" ");
                for(j=i;j>=1;j--)
                        printf("*");
                printf("\n");
        }
}


#include<stdio.h>
void main()
{
        int i,j;
        for(i=1;i<=4;i++)
        {
               for(j=1;j<=i;j++)
                        printf("* ");
                printf("\n");
        }
}

#include<stdio.h>
void main()
{
 int i,j,k;
 for(i=1;i<=4;i++)
 {
  for(k=4;k>i;k--)
   printf(" ");
  for(j=1;j<=i;j++)
   printf("* ");
  printf("\n");
 }

}

//program to find if no is odd parity or even parity
#include<stdio.h>
void main()
{
        int a,i,count=0;
 printf("Enter a number\n");
 scanf(" %d",&a);
        for(i=7;i>=0;i--)
        {
                if((a & (1<<i))!=0)
                        count++;
              
        }
 if(count%2==0)
  printf("No. is even parity");
 else
  printf("No. is odd parity");
}


//Program to remove leading zeros in binary form of a number
#include<stdio.h>
void main()
{
 int a,i,j,pos;
 printf("Enter a number\n");
 scanf("%d",&a);

 for(i=7;i>=0;i--)
 {
  if((a & (1<<i))!=0)
  {
   pos = i;
   break;
  }
 }
  for(j=pos;j>=0;j--)
         {
                if((a & (1<<j))==0)
                        printf("0 ");
                else
                        printf("1 ");
             
        }
}


#include<stdio.h>
main()
{
 char a;
 int i,len,flag=0;
 printf("enter the string\n");
 gets(a);
 len=strlen(a);
 for(i=0;i<len;i++)

  if(a[i]==a[len-i-1])
  flag=flag+1;

 if(flag=len)
  printf("the string is palindrom\n");
 else
  printf("the string is not a palindrom\n");
}
/*#include<stdio.h>
main()
{
 int i,j,n,prime;
 printf("find the prime number between 1 to n:\n");
 scanf("%d",&n);
 printf("the prime numbers between 1 to %d:",n);
 for(i=2;i<=100;i++)
 {
  for(j=2;j<=i/2;j++)
  {
   if(i%j==0)
   {
    prime=0;
    break;
   }
  }
 }
 if(prime=1)
 {
  printf("%d\n",i);
 }
 return 0;
}*/




//program to show use of extern variable
#include<stdio.h>
int x=10;
void main()
{
 extern int y;
 printf("%d %d\n",x,y);
}
int y=20;


#include<stdio.h>
int fun()
{
 static int a=10;
 a-=2;
 return a;
}
void main()
{
 for(fun();fun();fun())
  printf("%d\n",fun());
}

#include<stdio.h>
void main()
{
 int x,y,z;
 x=2,y=1,z=0;
 z+= -x++ + ++y;
 printf("%d%d%d\n",x,y,z);
 z= ++x || y++ && ++z;
 printf("%d%d%d\n",x,y,z);
 x=2; y=2; z=2;
 z+= x<y? x++ : y++;

 printf("%d%d%d",x,y,z);

 
}

#include<stdio.h>
void main()
{
 float a=5;
 int b=8,c=4,res =0;
 res = a * b % c;
 printf("res = %d",res);
}

#include<stdio.h>
int a=10;
void main()
{
 int a=30;
 {
  extern int a;
  printf("%d\n",a);
 }
}

#include<stdio.h>
void main()
{
 int num;
 printf("Enter a number\n");
 scanf("%d",&num);
 if(num & 1 == 1)
  printf("Odd");
 else
  printf("Even");
}

#include<stdio.h>
void main()
{
 char ch=0x12;
 char x,y;
 printf("Before swapping the nibble %x",ch);
 x=0xf0 & ch;
 y=0x0f & ch;
 x=x>>4;
 y=y<<4;
 ch=x|y;
 printf("\nAfter swaaping the nibble %x",ch);
}

#include<stdio.h>
void main()
{
 int a[3][3];
 int i,j;
 printf("Enter array elements\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
   scanf("%d",&a[i][j]);
 }
 printf("The matrix is:\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   printf("%d ",a[i][j]);
  }
  printf("\n");
 }
}


//Program to find greatest among three numbers using nested if else
#include<stdio.h>
void main()
{
 int a,b,c;
 printf("Enter three numbers\n");
 scanf("%d%d%d",&a,&b,&c);
 if(a>b)
 {
  if(a>c)
   printf("a is greater");
  else
   printf("c is greater");
 }
 else
 {
  if(b>c)
   printf("b is greater");
  else
   printf("c is greater");
 }
}

#include<stdio.h>
static int a;  //global static variable
//int a;  // global variable                  
void fun()
{
 a++;
 printf("%d\n",a);
}
void main()
{
 int a=10; //local variable or static local variable hide the global variable within the block
 fun();
 printf("%d",a);
}

#include<stdio.h>
void fun1();
void fun2();
void main()
{
 fun1();
 printf("Inside mainn\n");
}

void fun1()
{
 printf("Before calling in fun1\n");
 fun2();
 printf("Inside fun1\n");
}
void fun2()
{
 printf("Inside fun2\n");
}

#include<stdio.h>
extern int a;
void fun()
{
 printf("%d\n",a);
}

#include<stdio.h>
static int a=10;
void fun();
void main()
{
 fun();
}

//Program to find fibonacci series
#include<stdio.h>
void main()
{
 int a=0,b=1,c,num,i=2;
 printf("Enter length of fibonacci series\n");
 scanf("%d",&num);

 printf("The fibonacci series is: ");
 printf("%d %d ",a,b);
 while(i<num)
 {
  c=a+b;
  printf("%d ",c);
  a=b;
  b=c;
  i++;
 }
}

//Program to find factorial of a number
#include<stdio.h>
void main()
{
 int num,i;
 long int fact=1;
 printf("Enter a number\n");
 scanf("%d",&num);
 for(i=1;i<=num;i++)
 {
  fact *=i;
 }
 printf("Fatorial of %d is: %ld",num,fact);
}


#include<stdio.h>
void setbit(char num,int pos)
{
 num = num | (1<<pos);
 printf("%x\n",num);
}
void clearbit(char num,int pos)
{
 num = num & ~(1<<pos);
 printf("%x\n",num);
}
void togglebit(char num,int pos)
{
 num = num ^ (1<<pos);
 printf("%x\n",num);
}
#include<stdio.h>
void setbit(char,int);
void clearbit(char,int);
void togglebit(char,int);
void main()
{
 char num;
 printf("Enter a number\n");
 scanf("%d",&num);
 int pos, choice;
 while(1)
 {
  printf("\nMENU\n1.setbit\n2.clearbit\n3.toggle bit\n4.exit\n");
  printf("Enter your choice\n");
  scanf("%d",&choice);
  if(choice ==4)
   exit(0);

  printf("\nEnter pos of bit\n");
  scanf("%d",&pos);
  switch(choice)
  {
   case 1: setbit(num,pos);
    break;
   case 2: clearbit(num,pos);
    break;
   case 3: togglebit(num,pos);
    break;
   default: printf("Invlaid choice!!!!!");
  }
 }
}

#include<stdio.h>
void fun(register int a)
{
 printf("%d\n",a);
}
void main()
{
 register int a=10;
 fun(a);
}

#include<stdio.h>
int main()
{
 int a;
 printf("Enter a value\n");
 scanf("%d",&a);
 printf("\n%d",a);

 printf("\nEnter the same value\n");
 scanf("%i",&a);
 printf("\n%i",a);
}

#include<stdio.h>
int a;
int a=12;
int a;
int b;
void main()
{
 b=a;
 printf("%d%d\n",a,b);
}
#include<stdio.h>
void main()
{
 char str[]="aaabbbb cc ddd";
 int count=1,i;
 for(i=0;str[i]!='\0';i++)
 {
  while(str[i]==str[i+1])
  {
   count ++;
   i++;
  }
  if(str[i]!=str[i+1])
  { 
   if(str[i]==' ')
    printf("%dspace ",count);
   else
    printf("%d%c ",count,str[i]);
   count =1;
  }
 }
}


#include<stdio.h>
#define max 4
void main()
{
 #ifndef max
  printf("Not defined true\n");
 #else
  printf("defined");
 #endif
}

#include<stdio.h>
#define max 4
int main()
{
 int a=6;
 #if max>a   //a value is taken as zero
  printf("Inside if\n");
  printf("Inside if\n");
  printf("Inside if\n");
 #else
  printf("Inside else\n");
  printf("Inside else\n");
  printf("Inside else\n");
 #endif
}

#include<stdio.h>
void main()
{
// int a=10,b=20,c;
// c=printf("%d",a) + ++b;
// printf("%d",c);
// printf("%s","cranes"[1]);// segmentation fault
 char ch[]="cranes";
// printf("%s",ch[1]);// sementation fault
 printf("%s",&ch[1]);
 printf("%s",&"cranes"[1]);
}
#include<stdio.h>
#define max(a,b) (a>b?a:b)
int main()
{
 int x;
 x=max(3+2,2+7);
 printf("%d",x);
}

#include<stdio.h>
#define f(a,b) a*b
#define g(c,d) c+d
int main()
{
 printf("%d",f(4,g(5,6)));
}

#include<stdio.h>
#define calc(a,b) (a*b)/(a-b)
void main()
{
 int a=20,b=10;
 printf("%d",calc(a+4,b-2));
}

#include<stdio.h>
void main()
{
 int i,j;
 for(i=j=0;i<5||j<10;i++,j++)
  printf("%d %d\n",i,j);
}

#include<stdio.h>
void main()
{
 int a,b;
 for(a=0;a<10;a++);
  for(b=25;b>9;b-=3);
   printf("%d%d",a,b);
}

#include<stdio.h>
void main()
{
 int k=5;
 if(++k < 5 && k++ /5 || ++k < 8);
  printf("%d",k);
}



#include<stdio.h>
#include<stdlib.h>
void add(int, int);
void sub(int, int);
void mul(int, int);
void dive(int, int);

void main()
{
 int choice,a,b;
 while(1)
 {
  printf("\nCALCULATOR\n\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exit\n");
  printf("Enter ur choice\n");
  scanf("%d",&choice);
  if(choice==5)
  exit(0);
  printf("\nEnter two numbers\n");
  scanf("%d %d",&a,&b);
  switch(choice)
  {
   case 1: add(a,b);
    break;
   case 2: sub(a,b);
    break;
   case 3: mul(a,b);
    break;
   case 4: dive(a,b);
    break;
   default: printf("Invalid choice!!!!!");
 } }
}
void add(int a, int b)
{
 printf("Sum is: %d",a+b);
}
void sub(int a, int b)
{
        printf("Difference is: %d",a-b);
}
void mul(int a, int b)
{
        printf("Product is: %d",a*b);
}
void dive(int a, int b)
{
        printf("Quotient is: %d",a/b);
}


#include<stdio.h>
void main()
{
 int a=0x1234;
 int x,y;
 printf("Before %x",a);
 x=0xff00 & a;
 y=0x00ff & a;
 x=x>>8;
 y=y<<8;
 a=x|y;
 printf("\nAfter %x",a);

}

#include<stdio.h>
int arms(int);
void main()
{
 int n;
 printf("Enter a number\n");
 scanf("%d",&n);
 int res = arms(n);

 if(res ==1)
  printf("Armstrong");
 else
  printf("Not armstrong");
}
int arms(int num)
{
 int digit,sum=0,temp;
 temp = num;
 while(num>0)
 {
  digit = num%10;
  sum += (digit * digit * digit);
  num /=10;
 }
 if(sum == temp)
  return 1;
 else
  return -1;
}
//Program to find if all the bits of an integer is one or not
#include<stdio.h>
void main()
{

 char a;
 int i,c=0; 
 printf("Enter a number\n");
 scanf("%c",&a);

 for(i=7;i>=0;i--)
 {
  if((a & (1<<i))==0)
  {
   c=1;
   break;
  }
 }
 if(c == 0)
  printf("All the bits are 1");
 else
  printf("All the bits are not 1");
}

#include<stdio.h>
void main()
{
        int a[3][3],b[3][3],c[3][3];
        int i,j;
        printf("Enter matrix a\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                        scanf("%d",&a[i][j]);
        }
        printf("\nEnter matrix b\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        scanf("%d",&b[i][j]);
                }
        }
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                       c[i][j]=a[i][j]+b[i][j];
                }
        }
 printf("\nThe sum of matrices is:\n");
        for(i=0;i<3;i++)
        {
                for(j=0;j<3;j++)
                {
                        printf("%d\t",c[i][j]);
                }
                printf("\n");
        }
}



#include<stdio.h>
struct student
{
 char name[20];
 int rollno;
}s1[4];
void display(void *);
int main()
{
 int i;
 printf("Enter the details");
 for(i=0;i<4;i++)
 {
  printf("Enter name:\n");
  scanf("%s",s1[i].name);
  printf("Enter roll no:\n");
  scanf("%d",&s1[i].rollno);

 }
 display(&s1[0]);
}
void display(struct student *s1)
{
 int i;
 printf("Dereferenece through void ponter:\n");
 for(i=0;i<4;i++)
 {
 printf("Name: %s\n",((struct student *)s1)->name);
 printf("Rollno: %d\n",((struct student*)s1)->rollno);
 s1=s1+(sizeof(struct student));

 }
}
#include<stdio.h>
#include<string.h>
int main()
{
 char ch[30];
 fgets(ch,30,stdin);

}
#include<stdio.h>
int main()
{
 char a[10]="aditya";
 char x;
 char *p=a;
 x=printf("%c",a);
 printf("%d\n",x);
 x=printf("%c\n",*p);
 printf("%d",x);
}

#include<stdio.h>
#define sz 12
#define num 3
struct employee
{
        int emp_id;
        char name[10];
        char dept[sz];
        char desg[sz];
};
/*void dispdept(struct employee emp[],char ch[])
{
        int count=0;
        int j;
         printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
        for(j=0;j<num;j++)
        {
                if((strcmp(emp[j].dept,ch) == 0))
                {
                        printf("%d\t\t%s\t\t%s\t\t%s\n",emp[j].emp_id,emp[j].name,emp[j].dept,emp[j].desg);
                        count++;
                }
                else
                        continue;

        }
        if(count == 0)
                printf("Not Found\n");
}
*/
int main()
{
        int i,k,flag,key;
        char ch[10];
       
        struct employee emp[5];
        printf("Enter the details:\n");
        for(i=0;i<num;i++)
        {
  flag=0;
                printf("Employee no:%d\n",i);
                printf("Employee Id:\n");
                scanf("%d",&emp[i].emp_id);
                 
  for(k=0;k<i;k++)
  {
   if(emp[i].emp_id == emp[k].emp_id)
   {

    flag+=1;

   }


  }               
  if(flag != 0)
  {
  printf("ENTRY DUPLICACY\n");
  i--;
                printf("Employee Id:\n");
                scanf("%d",&emp[i].emp_id);

  }

          else
  {
                 printf("Employee name\n");
                 scanf("%s",emp[i].name);
                 printf("Employee Department\n");
                 scanf("%s",emp[i].dept);
                 printf("Employee Designation\n");
                 scanf("%s",emp[i].desg);
  }
  
        }
        printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
 for(i=0;i<num;i++)
        {
 
  printf("%d\t\t%s\t\t%s\t\t%s\n",emp[i].emp_id,emp[i].name,emp[i].dept,emp[i].desg);
 }

}



#include<stdio.h>
#include<stdlib.h>
int stack1[20];
int stack2[20];
int top1=-1, top2=-1;
void push(int c)
{
 char ch;
 if(top2 == -1)
 {
  printf("Enter the number to be inserted:");
  scanf(" %d",&c);
  top1=top1+1;
  stack1[top1]=c;

 }
 else
 {
  while(top2 != -1)
  {
   top1 = top1+1;
   stack1[top1]=stack2[top2];
   top2=top2+1;

  }


 }
}
int pop()
{
 int val;
 while(top1 != -1)
 {
  top2=top2+1;
  stack2[top2]=stack1[top1];
  top1=top1-1;


 }
 val= stack2[top2];
 top2=top2-1;
 while(top2 != -1)
 {
  top1=top1+1;
  stack1[top1]=stack2[top2];
  top2=top2-1;
 }
 return val;
}

void display()
{
 int i;
 printf("STACK ELEMENTS ARE\n");
 for(i=0;i<= top1;i++)
 {
  printf("%d ",stack1[i]);
 }
}
int main()
{
    int choice, value,item;
    char ch;
   
     do
     {
     printf("1.Insert\n2.Display\n3.Delete\n");
        printf("Enter your choice for the operation: ");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:
              push(item);
              break;
            case 2: 
              display();
              break;
            case 3:
              item=pop();
              printf("\nThe item deleted is %d\n",item);
              break;
            default:
              printf("Wrong choice\n");
             break;
        }
        printf("Do you want to continue\n");
        scanf(" %c",&ch);
        }while(ch == 'y');
  
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee
{
        int emp_id;
        char name[10];
        char dept[12];
        char desg[12];
};
void dispall(struct employee emp[])
{
 int i;
 printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
  for(i=0;i<3;i++)
         {
   printf("%d\t\t%s\t\t%s\t\t%s\n",emp[i].emp_id,emp[i].name,emp[i].dept,emp[i].desg);
  }

}

void deprtmnt(struct employee emp[],char ch[])
{
        int count=0;
        int j;
         printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
        for(j=0;j<3;j++)
        {
                if((strcmp(emp[j].dept,ch) == 0))
                {
                        printf("%d\t\t%s\t\t%s\t\t%s\n",emp[j].emp_id,emp[j].name,emp[j].dept,emp[j].desg);
                        count++;
                }
                else
                        continue;

        }
        if(count == 0)
                printf("Not Found\n");

}
void desgntion(struct employee emp[],char ch[])
{
        int count=0;
        int j;
         printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
        for(j=0;j<3;j++)
        {
                if((strcmp(emp[j].desg,ch) == 0))
                {
                        printf("%d\t\t%s\t\t%s\t\t%s\n",emp[j].emp_id,emp[j].name,emp[j].dept,emp[j].desg);
                        count++;
                }
                else
                        continue;

        }
        if(count == 0)
                printf("Not Found\n");

}



void alpha(struct employee emp[],char ch[])
{
 int i,count=0;
  printf("EMP_ID\t\tNAME\t\tDepartment\tDesignation\n");
 
 for(i=0;i<3;i++)
 {

  if(strncmp(emp[i].name,ch,1) == 0)
  {
                        printf("%d\t\t%s\t\t%s\t\t%s\n",emp[i].emp_id,emp[i].name,emp[i].dept,emp[i].desg);
                        count++;
                }
                else
                        continue;

        }
        if(count == 0)
                printf("Not Found\n");


}


int main()
{
 int i,ch,ch1,ch2;
 char dept[10];
 char f[10];
 char dsgn[10];
 struct employee emp[5];
        printf("Enter the details:\n");
         for(i=0;i<3;i++)
        {

                printf("Employee no:%d\n",i);
                printf("Employee Id:\n");
                scanf("%d",&emp[i].emp_id);
                printf("Employee name\n");
                scanf("%s",emp[i].name);
                printf("Employee Department\n");
                scanf("%s",emp[i].dept);
                printf("Employee Designation\n");
                scanf("%s",emp[i].desg);
 }
 printf("MENU\n1.SEARCH\n2.DISPLAY\n3.EXIT\n");
 printf("Enter your choice:\n");
 scanf("%d",&ch);

 switch(ch)
 {

  case 1:
   printf("WHICH TYPE OF SEARCH DO YOU WANT\n1.DEPARTMENT-WISE ALL\n2.DESIGNATION-WISE\n3.EXIT\n");
   printf("Enter your choice\n");
   scanf(" %d",&ch1);
   switch(ch1)
   {
    case 1:
     printf("Enter the department you want to search\n");
     scanf(" %s",dept);
     deprtmnt(emp,dept);
     break;
    case 2:
     printf("Enter the designation to be searched\n");
     scanf(" %s",dsgn);
     desgntion(emp,dsgn);
    default:
     printf("EXITING\n");
     exit(0);

   }
   break;
  case 2:
   printf("WHICH TYPE OF DISPLAY DO YOU WAANT\n1.BY NAME'S FIRST LETTER\n2.DISPLAY ALL\n");
   printf("Enter your choice\n");
   scanf(" %d",&ch2);
   switch(ch2)
   {
    case 1:
     printf("Enter the 1st alphabet for search\n");
     scanf(" %s",f);
     alpha(emp,f);
     break;
 
    case 2:
     dispall(emp);
     break;

 
    default: exit(0);

   }
   break;

   default:
    exit(0);

 }


}

#include<stdio.h>
int main()
{
int a;
 do
 {
  scanf("%d", &a);



 }
 while(a == 1)
 {
 printf("subham\n");
 };

}






#include <stdio.h>
#include<stdlib.h>
struct st{

int a;
   
};

struct st k;
typedef struct st k1;
k1  fun(struct st m)
{
    m.a=12;
   // printf("%d",m.a);
   return(m);
}
int main()
{
    printf("Hello World");
k1 g=fun(k);

printf("%d",g.a);
   
}






Comments

Popular posts from this blog

C in Depth

circular linked list

TYPES OF DATA TYPES AND DEACLARING IN A SINGLE LINE FORMATE