Search This Blog

Thursday, 23 November 2017

Array Implementation of stack and queue YouTube Videos : C Programming

Array Implementation of stack.




Array Implementation of queue.


Structure and Union YouTube Videos : C Programming



Youtube videos on Structure and Union.




Addition of polynomials : C Program

/* Addition of polynomials */

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

void main()
{
 int poly[10][10],sum[10],i,j,k,no;
 clrscr();

 printf("\n How many polynomials you want to add : ");
 scanf("%d",&no);

 printf("\nEnter %d polynimials : \n",no);
 for(i=0;i<no;i++)
 {
  printf("\nEnter a,b,c,d for ax^2+bx^1+c=d  for polynomial no %d : ",i+1);
  for(j=0;j<4;j++)
  {
   scanf("%d",&poly[i][j]);
  }
 }

 //addition logic
 k=0;
 for(i=0;i<4;i++)
 {
  sum[k]=0;
  for(j=0;j<no;j++)
  {
   sum[k]=sum[k]+poly[j][i];
  }
  k=k+1;
 }

 printf("\nResultant Equation : %dx^2 + %dx^1 + %d = %d ",sum[0],sum[1],sum[2],sum[3]);
 getch();
}

Output screens :




Click here : How to Add polynomials - @jay

WAP to accept two strings and concatenate them without using string functions : C Program

/* WAP to accept two strings and concatenate them without using string functions */

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

void main()
{
 char str1[20],str2[20],ch;
 int i,j,len=0;
 clrscr();

 printf("Enter 1st string : ");
 scanf("%s",&str1);
 printf("Enter 2nd string : ");
 scanf("%s",&str2);

 printf("\nBefore concatenate : \n");
 printf("String 1 : %s",str1);
 printf("\nString 2 : %s",str2);

 //calculating length of 1st string
 for(i=0;str1[i]!=0;i++)
 {
  len=len+1;
 }

 //concatenate logic without string function
 for(i=len,j=0;str2[j]!=0;i++,j++)
 {
  str1[i]=str2[j];
 }
 str1[i]='\0';//mentioning end of string

 printf("\nAfter concatenate : \n");
 printf("String 1 : %s",str1);
 printf("\nString 2 : %s",str2);

 getch();
}

Output screens :


Tuesday, 31 October 2017

Display content of file : C Program

/*Basic file handling programs.
    Display content of file. */

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

void main()
{
 FILE *fp;
 char ch;
 clrscr();
 fp=fopen("ajay.txt","r");

 if(fp==NULL)
 {
  printf("Error occured while opening file");
 }
 else
 {
  printf("\n***************** File Content *****************\n");
  while(1)
  {
   ch=getc(fp);
   if(ch==EOF)
   {
    break;
   }
   printf("%c",ch);
  }
  printf("\n************* End of  File Content **************\n");
 }
 fclose(fp);
 getch();
}


Output Screens :

Insert and delete an element at given position in array : C Program

/* Insert and delete an element at given position in array : C Program */

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

void main()
{
 int arr[20],number,location,count,i,choice;
 clrscr();
 printf("\n Enter count for array : ");
 scanf("%d",&count);
 printf("\n Enter %d Elements : \n",count);
 for(i=0;i<count;i++)
 {
  printf(" arr[%d] : ",i+1);
  scanf("%d",&arr[i]);
 }
 while(1)
 {
  printf("\n 1. insert array element \n 2. delete array element \n 3. exit\n Enter Choice : ");
  scanf("%d",&choice);
  if(choice==1)
  {
   printf("\nEnter element to be added in array : ");
   scanf("%d",&number);
   printf("\nEnter position for entered element : ");
   scanf("%d",&location);
   /* creating space for element */
   for(i=count;i>=location;i--)
   {
    arr[i]=arr[i-1];
   }
   count=count+1;
   arr[location-1]=number;
   /* displaying entire array */
   for(i=0;i<count;i++)
   {
    printf("\n arr[%d] : %d",i+1,arr[i]);
   }
  }
  else if(choice==2)
  {
   printf("\nEnter position for deleting element : ");
   scanf("%d",&location);
   /* creating space for element */
   while(location<count)
   {
    arr[location-1]=arr[location];
    location=location+1;
   }
   count=count-1;
   /* displaying entire array */
   for(i=0;i<count;i++)
   {
    printf("\n arr[%d] : %d",i+1,arr[i]);
   }
  }
  else if(choice==3)
  {
   exit(0);
  }
  else
  {
   printf("\nPlease enter correct choice ");
  }
 }
 getch();
}


Output Screens :


Convert number into words : C program

/* Convert number into words : C program */

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

void main()
{
 int no,rev=0,rem,temp;
 clrscr();
 printf("\nEnter Number : ");
 scanf("%d",&no);
 temp=no;
 while(temp>0)
 {
  rem=temp%10;
  rev=rev*10+rem;
  temp=temp/10;
 }
 temp=no;
 while(temp>0)
 {
  rem=temp%10;
  switch(rem)
  {
   case 0 : { printf(" zero "); break;}
   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;}
   case 6 : { printf(" six "); break;}
   case 7 : { printf(" seven "); break;}
   case 8 : { printf(" eight "); break;}
   case 9 : { printf(" nine "); break;}
  }
  temp=temp/10;
 }
 getch();
}

Output Screens :