Thursday, 8 November 2012

WAP to accept an amount from the user and display the number of different denominations.

WAP to accept an amount from the user and display the number of different denominations.
INPUT: 1288
OUTPUT: No. of notes of Rs.100 = 12
                No. of notes of Rs.50 = 1
                No. of notes of Rs.20 = 1
                No. of notes of Rs.10 = 1
                No. of notes of Rs.5 = 1
                No. of notes of Rs.2= 1
                No. of notes of Rs.1 = 1
#include <stdio.h>
void main()
{
    int note[]={100,50,20,10,5,2,1};
    int i,n,amt;
    printf("Enter the amount");
    scanf("%d",&amt);
    for(i=0;i<7;i++)
    {
        n=amt/note[i];
        if(n!=0)
        printf("The no. of notes of Rs.%d= %d\n",note[i],n);
        amt=amt%note[i];
    }
}

WAP to enter a natural number and Display all the possible combination of consecutive numbers

  • WAP to enter a natural number and Display all the possible combination of consecutive numbers which add up the give the sum equal to the original number.
INPUT: 15
OUTPUT: 1 ,2 ,3, ,4 ,5.
               4 , 5, 6.
#include <stdio.h>
void main()
{
    int i,j,k,no,sum;
    printf("Enter a number\n");
    scanf("%d",&no);
    for(i=1;i<no/2;i++)
    {
        for(j=1;j<no;j++)
        {
            sum=0;
            for(k=i;k<=j;k++)
            sum=sum+k;
            if(sum==no)
            {
                for(k=i;k<=j;k++)
                printf("%d ,",k);
                printf("\n");
            }
        }
    }
}

WAP to to enter a string and Print the consecutive character.

  • WAP to to enter a string and Print the consecutive character.

INPUT:  UNDERSTANDING COMPUTER APPLICATION
OUTPUT:  D and E are consecutive characters.
                  R and S are consecutive characters.
                  S and T are are consecutive characters.  
#include <stdio.h>
void main()
{
    char a[100];
    int i;
    printf("Enter a String\n");
    scanf("%s",&a);
    for(i=0;i!='\o';i++)
    {
        if((int)a[i]==((int)a[i+1]-1))
        printf("%c and %c are consecutive characters\n",a[i],a[i+1]);
    }
}

Wednesday, 7 November 2012

WAP to print the possible combination of a Three Letter Word.

  • WAP to print the possible combination of a Three  Letter Word.
               INPUT:        TOP
               OUTPUT:    TOP
                                  TPO
                                  OTP
                                  OPT
                                  PTO
                                  POT                             
#include <stdio.h>
void main()
{
    int i,j,k;
    char str[10];
    printf("Enter a three letter word");
    scanf("%s",&str);
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
            if((i!=j)&&(j!=k)&&(k!=i))
            printf("%c%c%c\n",str[i],str[j],str[k]);
            }
        }
    }
    }

WAP to perform BINARY search.

  • WAP to perform BINARY search.(Bubble Sorting needed) .
#include <conio.h>
void main()
{
    int a[10],i,j,num,lb=0,ub=9,mid;
    printf("Enter the array element");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    printf("Enter the search element");
    scanf("%d",&num);
//Bubble Sort
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            //Ascending Order
            if(a[i]>a[j])
            a[i]=(a[i]+a[j])-(a[j]=a[i]);
        }
    }
//Searching Process
    while(lb<=ub)
    {
        mid=(lb+ub)/2;
        if(num==a[mid])
        break;
        if(num>a[mid])
        lb=mid+1;
        else
        ub=mid-1;
    }
    if(lb>ub)
    printf("Not Found");
    else
    printf("Found");
    }

WAP to sort an array with Selection Sort technique(Ascending Oder)

  • WAP to sort an array with Selection Sort technique(Ascending Oder)
#include <stdio.h>
#include <conio.h>
void main()
{
    int a[10],i,j,c;
    printf("Enter the array element");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    for(i=0;i<10;i++)
    {
        c=i;
        for(j=i+1;j<10;j++)
        {
            //Ascending Order
            if(a[i]>a[j])
            c=j;
        }
        a[i]=(a[i]+a[c])-(a[c]=a[i]);//one line swapping
    }
     printf("The sorted array is:");
     for(i=0;i<10;i++)
     printf("%d ",a[i]);
    }

WAP to sort an array Using BUBBLE sort(Ascending Order).

  •  WAP to sort an array Using BUBBLE sort(Ascending Order).
#include <stdio.h>
#include <conio.h>
void main()
{
    int a[10],i,j;
    printf("Enter the array element");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            //Ascending Order
            if(a[i]>a[j])
            a[i]=(a[i]+a[j])-(a[j]=a[i]); // one line swapping.
        }
    }
     printf("The sorted array is:");
     for(i=0;i<10;i++)
     printf("%d ",a[i]);
    }

21 MATCH STICK GAME .

  • MATCH STICK GAME
#include <stdio.h>
void main()
{
    int matchs=21,user,comp;
    printf("\n THREE GOLDEN RULE:");
    printf("\n 1. You have 21 match stick");
    printf("\n 2. You have to choose matchstick from 1 to 4");
    printf("\n 3. Computer always wins");
    while(matchs>1)
    {
        if(matchs==1)
        break;
        printf("\n Your turn:");
        printf("\n Matchsticks remaining %d ",matchs);
        printf("\n Pick your match stick 1 to 4:");
        scanf("%d",&user);
        comp=5-user;
        printf("\n Computer turn:");
        printf("\n Compter choose %d",comp);
        matchs=matchs-user-comp;
        }
        printf("\n 1 matchsticks remains for you");
        printf("\n Computer Wins");
        }