Thank you all for being with us.
Learn, Create and Implement.

  • Build Concept

    You can build your concept in programming on programsway.com.

  • Examples

    There are many C Programming examples on programsway.com.

  • Ask Questions

    Ask questions and get quick answers. Request any program and we will publish that program.

  • Friday, 17 May 2013


    This is a program to convert binary to decimal
    /* author- WYES KARNY */
    #include<stdio.h>
    int main()
    {
      int a,rem,des=0,i=1;
    printf("Enter a binary number ");
    scanf("%d",&a);
    while(1)
    {
    rem=a%10;
    a=a/10;
    des+=rem*i;
    i=i*2;
    if(a==0)
    break;
    }
    printf("\nThe equevalent desimal value is %d \n",des);
    return 0;
    }

    And for the Decimal to binary
    #include<stdio.h>
    int main()
    {
    int a,i,shift,bit;
    scanf("%d",&a);
    for(i=0;i<16;i++)
    {
    shift=a<<i;
    shift=shift>>15;
    bit=shift&1;
    if(bit==1)
    printf("1");
    else
    printf("0");
    }
    }

    Friday, 10 May 2013

    Linked List is collection of data which is linked together in a specific way.
    It is very efficient for computer memory. It consumes memory usage and save memory spaces.
    It works as Dynamic Allocation System (DMA).
    First we have to know -

    1. What is Linked List?
    2. Why we use Linked List?
    3. How do we implement Linked list?
    We will find answers for all of these questions.
    I have given some introduction of linked list above but did not define yet.
    Linked List is a list consisting element of structure type, which contains the data and link to the next element.
    The picture can clear your confusion.
    Here every block represents an element of the linked list. Every block contains two sub-blocks.
    One block is for the data, saved in the element and other for the link to the next element.

    Next question is, why we use it. Let us consider an example, in a school, there is a class consisting 50 students. If we save their marks in an array according to their roll numbers, then we have to declare an array of 50 elements. If we do this then when a new student gets admission, we have no space for the new student.
    If we declare an array of 100 elements at first then it would be possible but it wastes a huge memory space.
    Therefore in this case we can use Linked List.

    Next, implementation of linked list, 
    Here is a program to implement linked list.

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct link_list
    {
      int number;
      struct link_list *next;
    }l;

    void create(l *list);
    void print_list(l* list);

    main()
    {
      l *head;
      head=(l*)malloc(sizeof(l));
      create(head);
      print_list(head);
    }



    void create(l *list)
    {
      char c;
      printf("Enter the number\n");
      scanf("%d",&list->number);
      printf("continue...  ");
      getchar();
      c=getchar();
      if(c=='y')
      {
      list->next=(l*)malloc(sizeof(l));
      create(list->next);
      }
      else
      list->next=NULL;
    }




    void print_list(l* list)
    {
      if(list->next!=NULL)
      {
      printf("%d  ",list->number);
      print_list(list->next);
      }
      else
      printf("%d\n",list->number);
    }


    (If you have any question, feel free to ask me)

      

    Wednesday, 20 March 2013

    In Data Structures the program infix to post fix using stack is very important. There for here is an example for  this program. Here we use a stack named stack to store in-stack elements.
    /* This is a program to turn a infix expression into post-fix expression and then evaluate the expression */
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<ctype.h>

    void push(char);
    char pop();
    int prt(char);
    int eval(char *);


    int top=-1;
    char stack[30];

    main()
    {
      int i=0,k=0;
      char infix[30],postfix[30];
      printf("Enter the expression ");
      scanf("%s",infix);
      for(i=0;i<strlen(infix);i++)
        {
        if(isdigit(infix[i]))
        postfix[k++]=infix[i];
        else if(top==-1||prt(infix[i])>prt(stack[top]))
    {
    postfix[k++]=' ';
    push(infix[i]);
    }
    else
    {
         while(prt(infix[i])<=prt(stack[top])&&top>-1)
    postfix[k++]=pop();
         push(infix[i]);
         }
    }
    while(top>-1)
    postfix[k++]=pop();
         postfix[k]='\0';
    printf("The postfix expression is %s\n",postfix);
    printf("The result is %d\n",eval(postfix));
    }

    void push(char a)
    {
    stack[++top]=a;
    return;
    }

    char pop()
    {
    return stack[top--];
    }

    int prt(char a)
    {
    if(a=='+'||a=='-') return 1;
    else if(a=='*'||a=='/') return 2;
    }

    int eval(char *str)
    {
      int a[30],i,n=-1,j=0;
      char temp[5];
      for(i=0;str[i]!='\0';i++)
      {
        if(isdigit(str[i]))
    temp[j++]=str[i];
        else if(str[i]==' ')
    {
    temp[j]='\0';
    a[++n]=atoi(temp);
    j=0;
    }
    else
    {
    if(j!=0)
    {
    temp[j]='\0';
    a[++n]=atoi(temp);
    j=0;
    }
    if(str[i]=='+')
    a[n-1]=a[n-1]+a[n];
    else if(str[i]=='-')
    a[n-1]=a[n-1]-a[n];
    else if(str[i]=='*')
    a[n-1]=a[n-1]*a[n];
    else if(str[i]=='/')
    a[n-1]=a[n-1]/a[n];
    n--;
    }
      }
      return a[0];
    }

    The output of this program......









    Sunday, 10 March 2013


    This is a program show the applications the mod (%) operation.

    /*This is a program to input three digit number from user and display square of first and last number */
    #include<stdio.h>
    int main()
    {
    int num,rem,sqr1,sqr2;
    start:
    printf("Enter a three digit number  ");
    scanf("%d",&num);
    if(num>999){
    printf("\nSorry you have Entered long number\n");
    goto start;
    }
    if(num<100){
    printf("\nSorry you have entered short number\n");
    goto start;
    }
    rem=num%10;
    sqr2=rem*rem;
    num=num/10;
    num=num/10;
    sqr1=num*num;
    printf("\nThe square of the first digit is %d and the square of the last digit is %d \n",sqr1,sqr2);
    return 0;
    }

    The output of this program ....

    Saturday, 9 March 2013

    In C every character has a ASCII number. Here we can use this concept for this program.
    First we take a input from user. Then we check whether it is an alphabet or not and also check whether it is  in capital or in small letter. If it is in capital then we add 32 with the character's ASCII value.
    If it is in small letter then we subtract  32 from the character's ASCII value.
                                              For your convenience here is the ASCII chart.

    Now the the example ....


    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
    char c;
    printf("Enter a  alphabet  ");
    scanf("%c",&c);
            if(isalpha(c))
            {
             if(c<'a')
               {
          c+=32;
          printf("\nYou have entered capital letter\nThe corresponding  small letter is  %c\n",c);
               }
            else
               {
                  c-=32;
                  printf("\nYou have entered small letter\nThe corresponding  capital letter is  %c\n",c);
                }
            }
    return 0;
    }

    The output of this program will be....

    Friday, 8 March 2013

    We can inter change values with out using third variable.


    //This is a program to interchange values of to number without using third variable

    #include<stdio.h>
    int main()
    {
    int a,b;
    printf("Enter the frist number ");
    scanf("%d",&a);
    printf("\nEnter the scond number ");
    scanf("%d",&b);
    a=a*b;
    b=a/b;
    a=a/b;
    printf("\nThe interchanged values are\nThe frist number is %d\nThe scond number is %d\n",a,b);
    return 0;
    }

    The output will be.....

    This is a simple program to swap the values using third variable.


    //This is a program to interchange vaules of to number using thrid variable
    #include<stdio.h>
    int main()
    {
    int fst_num,snd_num,trd_num;
    printf("Enter the frist number ");
    scanf("%d",&fst_num);
    printf("\nEnter the scond number ");
    scanf("%d",&snd_num);
    trd_num=fst_num;
    fst_num=snd_num;
    snd_num=trd_num;
    printf("\nThe interchanged values are\nThe frist number is %d\nThe scond number is %d\n",fst_num,snd_num);
    return 0;
    }

    The output of this program will be.....