Tuesday, 25 December 2012

WAP to enter numbers(Using File Handling) and print them.

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp;
    int n;
    fp=fopen("file.txt","w");
    do
    {
    printf("Enter a number(enter 0 to stop)");
    scanf("%d",&n);
    putw(n,fp);
    }
    while(n!=0);
    fclose(fp);
    fp=fopen("file.txt    ","r");
    while((n=getw(fp))!=EOF)
    printf("%d\n",n);
    fclose(fp);
    }

Monday, 26 November 2012

WAP to enter a number to sum it to Single Digit.(Using Recussion Function))

  • WAP to enter a number to sum it to Single Digit
                 Input: 1256
                 Output: 5
#include <stdio.h>
void cal(int *);
void main()
{
    int n;
    printf("Enter a number");
    scanf("%d",&n);
    cal(&n);
    }
    void cal(int *n)
    {
        int sum=0;
        while(*n>0)
        {
            sum=sum+*n%10;
            *n=*n/10;
            }
        if(sum<=9)
        printf("%d",sum);
        else
        cal(&sum);
        }

Monday, 19 November 2012

WAP to print the the second highest element in an array(using function).

  •  WAP to print the the second highest element in an array.(using function)
#include <stdio.h>
int second(int a[])
{
    int i,j,n;
    for(i=0;i<10;i++)
        for(j=i+1;j<10;j++)
            if(a[i]<a[j])
            a[i]=(a[i]+a[j])-(a[j]=a[i]);
    for(i=0;i<10;i++)
    {
        n=a[i+1];
        if(a[i]!=n)
        return n;
    }
    }
    void main()
    {
    int a[10],num,i;
    printf("Enter a array element");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    num=second(a);
    printf("%d is the second highest element",num);
    }

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