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

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

Sunday, 14 October 2012

WAP to enter an array and Sort it.

  •  WAP to enter an array and Sort it as Following:
 input:1 2 3 4 5 6 7
output: 6 4 2 1 3 5 7

#include <stdio.h>
#include <conio.h>
void main()
{
    int a[15],b[15];
    int goleft=0,bind=0,lind=14;
    //input of array
    printf("Enter the array");
    for(int i=0;i<15;i++)
    scanf("%d",&a[i]);
    //Sorting of array(Bubble Sort)
    for(i=0;i<15;i++)
    {
        for(int j=i+1;j<15;j++)
        {
         if(a[i]>a[j])
         {
            int t=a[i];
            a[i]=a[j];
            t=a[j];
            }
         }
        }

    for(i=14;i>=0;i--)
    {
        if(goleft==0)
          {
                b[lind]=a[i];
                lind--;goleft=1;
          }
          else
          {
            b[bind]=a[i];
            bind++;goleft=0;
            }
          }
          for(i=0;i<15;i++)
          printf("%d",b[i]);
        }

WAP to Find the Sum of Right Diagonal And Sum of Left Diagonal of a 3*3 array..

  •  WAP to Find the Sum of Right Diagonal And Sum of Left Diagonal.
#include <stdio.h>
#include <conio.h>
void main()
{
    int i,j,rd=0,ld=0;
    int a[3][3];
    printf("Enter the array");
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
     scanf("%d",&a[i][j]);
     }
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
        if(i==j)
        rd=rd+a[i][j];
        if(i+j==2)
        ld=ld+a[i][j];
        }
        }
        printf("\n left diagianl sum is %d",rd);
        printf("Right diagianl sum is %d",ld);
        }

Tuesday, 25 September 2012

WAP for Heart Pattern.

  
  • WAP for Heart Pattern. 
       *       *
      ***   ***
    **********
     ********
      ******
        ****
         ** 
#include <stdio.h>
#include <conio.h>
void main()
{
    int i,j;
    for(i=5;i>=1;i=i-2)
    {
        for(j=i;j>=1;j=j-2)
        printf(" ");
        for(j=5;j>=i;j--)
        printf("*");
        for(j=i;j>1;j--)
        printf(" ");
        for(j=5;j>=i;j--)
        printf("*");
        printf("\n");
        }
        for(i=1;i<=6;i++)
        {
            for(j=1;j<=i;j++)
            printf(" ");
            for(j=6;j>i;j--)
            printf("*");
            for(j=4;j>=i;j--)
            printf("*");
            printf("\n");
        }
        }

WAP to Find out the day of the entered year.(Gregorian Calender)

  •  According to Gregorian Calender it was Monday on the date 01/01/01.If any year is input through the keyboard. WAP to find out what is the day on 1st January of this Year.
#include<stdio.h>
#include<conio.h>
void main()
{
int y,d=0,i,ch=0;
clrscr();
printf("enter the year");
scanf("%d",&y);
for(i=1990;i<y;i++)
{
if(i%4==0)
d=d+366;
else
d=d+365;
}
ch=d%7;
switch(ch)
{
case 0:
printf("monday");
break;
case 1:
printf("tuesday");
break;
case 2:
printf("wednesday");
break;
case 3:
printf("thursday");
break;
case 4:
printf("friday");
break;
case 5:
printf("saturday");
break;
case 6:
printf("sunday");
break;
defaut:
printf("invalid option");
}
getch();
}


Saturday, 22 September 2012

WAP to print the pattern.

  • WAP to print the follwing pattern:
                           *
                         ***
                       *****
                     *******
#include <stdio.h>
#include <conio.h>
void main()
{
    int i,j,l,k;
    for(i=1;i<=5;i++)
    {
        for(j=4;j>=i;j--)
        printf(" ");
        for(l=1;l<=i;l++)
        printf("*");
        for(k=1;k<=i-1;k++)
        printf("*");
        printf("\n");
        }
        }

Tuesday, 4 September 2012

WAP to Find the net salary on basis of basic salary.

  • WAP to Find the net salary on basis of basic salary.

#include <stdio.h>
#include <conio.h>
void main()
{
    float bs,gs,ns,hra,da,pf;
    char c;
    printf("Enter 'f' for female and 'm' for male");
    scanf("%c",&c);
    printf("Enter the basic salary");
    scanf("%f",&bs);
    if(bs>=5000)
    {
        if(c=='f')
            {
            hra=(15/100)*bs;
            da=(10/100)*bs;
            pf=(8/100)*bs;
            }
            else
            {
            hra=(20/100)*bs;
            da=(15/100)*bs;
            pf=(10/100)*bs;
            }
        }
            else
            {
                hra=(10/100)*bs;
                da=(9/100)*bs;
                pf=(8/100)*bs;
                }

                gs=bs+hra+da;
                ns=gs-pf;
                printf("%f is the gross salary",gs);
                printf("%f is the net salary",ns);
            }

WAP to enter Lower And Upper Limit and Print the Cost.

  • WAP to enter Lower And Upper Limit and Print the Cost.
#include <stdio.h>
#include <conio.h>
void main()
{
    int up,lo,d;
    float s;
    clrscr();
    printf("enter the upper limit");
    scanf("%d",&up);
    printf("enter the lower limit");
    scanf("%d",&lo);
    d=up-lo;
    if((d>200)&&(d<500))
    s=d*3.50;
    if((d>100)&&(d<200))
    s=d*2.50;
    if(d<100)
    s=d*1.50;
    printf("the sum is %lf",s);
    getch();
   }

WAP to display the Name of days of Week.

  • WAP to display the Name of days of Week.
#include <stdio.h>
#include <conio.h>
void main()
{
    int ch;
    printf("Enter the day number");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:
        printf("Sunday");break;
        case 2:
        printf("Monday");break;
        case 3:
        printf("Tuesday");break;
        case 4:
        printf("Wednesday");break;
        case 5:
        printf("Thusday");break;
        case 6:
        printf("Friday");break;
        case 7:
        printf("Saturday");break;
        default:
        printf("Wrong Choice");
        }
        getch();
        }

Write a menu driven Program to covert no of years into second,minutes,hours,days and month.

  • Write a menu driven Program to covert no. of years into second,minutes,hours,days and month.
#include <stdio.h>
#include <conio.h>
void main()
{
    int yr;
    double f;
    int ch;
    printf("Enter the number of years");
    scanf("%d",&yr);
    printf("Enter your choise:\n");
    printf("1 for seconds\n");
    printf("2 for minutes\n");
    printf("3 for hours\n");
    printf("4 for days\n");
    printf("5 for months\n");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:
        f=yr*365*24*60*60;
        break;
        case 2:
        f=yr*365*24*60;
        break;
        case 3:
        f=yr*365*24;
        break;
        case 4:
        f=yr*365;
        break;
        case 5:
        f=yr*12;
        break;
        default:
        printf("Worng Choise");
    }
    }
    printf("%lf",f);
    }

WAP to find HFC and LCM of two number.

  •  WAP to find HFC and LCM of two number.
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b,c,p;
    printf("Enter two number to find LCM and HCF");
    scanf("%d\n",&a);
   scanf("%d",&b);
    p=a*b;
    do
    {
        c=(a%b);
        a=b;
        b=c;

        }
        while(a%b!=0);
        printf("HCF =%d",b);
        printf("LCM=%d",(p/b));
    }

WAP to check whether a number is an Armstrong Number or Not.

  •  WAP to check whether a num is an Armstrong Number or Not
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,num,s=0,n;
    printf("enter a number");
    scanf("%d",&n);
    num=n;
    while(n>0)
    {
        a=n%10;
        s=s+a*a*a;
        n=n/10;
        }
        if(num==s)
        printf("%d is a Armstrong Number",num);
        else
        printf("%d is NOT a Armstrong Number",num);
    }

Monday, 3 September 2012

WAP to Check For Palindrome Number

  •   WAP to Check whether a number to check if it is a palindrome or not.
#include <stdio.h>
void main()
{
    int n, reverse=0,temp;

    printf("Enter a number to check if it is a palindrome or not\n");
    scanf("%d",&n);
    temp = n;
    while( temp != 0 )
    {
        reverse = reverse * 10;
        reverse = reverse + temp%10;
        temp = temp/10;
    }

    if ( n == reverse )
        printf("%d is a palindrome number.\n", n);
    else
        printf("%d is not a palindrome number.\n", n);
}

WAP a program in C to print first 5 Prime Palindriome.

  • WAP a program in C to print first 5 Prime Palindriome.
#include <stdio.h>
#include <conio.h>
void main()
{
    int a=1,b=1,c=1,f,s,count;
    while(c>=5)
    {
        s=a+b;
        count=2;
        for(f=2;f<=s/2;f++)
        {
            if(s%f==0)
            {
                count++;
                break;
                }
                if(count==2)
                {
                printf("%d ",s);
                c++;
                    }
                a=b;
                b=s;
                }
            }
            getch();
        }
  • WAP to Intput a number and print its Binary and Hexa-decimal Equivalent.
#include <stdio.h>
#include <conio.h>
void main()
{
    int bind,hind,i,org,no,b[40],h[40];
    printf("Enter a number");
    scanf("%d",&no);
    org=no;
    bind=-1;
//Coverting to binary number
    while(no>0)
    {
        bind++;
        b[bind]=no%2;
        no=no/2;
        }
        hind=-1;
        no=org;
        //Coverting to Hexa-decimal number
        while(no>0)
        {
            hind++;
            h[hind]=no%16;
            no=no/16;
            }
//Printing binary number
            for(i=bind;i>=0;i--)
            printf("%d",b[i]);
            printf("\n");
//Printing hexa-decimal
            for(i=hind;i>=0;i--)
            {
                if(h[i]<=9)
                printf("%d",h[i]);
                else
                printf("%c",(char)h[i]+55);
                  }
                  }

Program to print Simple Pattern with C coding

Print the following pattern:
                                                            12345
                                                            2345
                                                            345
                                                            45
                                                            5
#include <stdio.h>
#include <conio.h>
void main()
{
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=i;j<=5;j++)
        printf("%d",j);
        printf("\n");
        }
        }
                                                          12345
                                                          1234
                                                          123
                                                          12
                                                          1
#include <stdio.h>
#include <conio.h>
void main()
{
    int i,j;
    for(i=5;i>=1;i--)
    {
        for(j=1;j<=i;j++)
        printf("%d",j);
        printf("\n");
        }
      }

Sunday, 2 September 2012

WAP to print fibonacci series till n terms(Using Goto)

  •  WAP to print fibonacci series till n terms(Using Goto)

#include <stdio.h>
#include <conio.h>
void main()
{
    int a=0,b=1,c,n=0;
    printf("\n%d",a);
    printf("\n%d",b);

    fib:
    c=a+b;
    n++;
    printf("\n%d",c);
    a=b;
    b=c;

    if(n<=10)
    goto fib;

    }

WAP to check if it is a KAPRYKAR number or not.

WAP to to input a number and check if it is a KAPRYKAR number or not.
Example:
(999)2=998001

99800+1=99801
9980+1=9981
998+1=999
So its a KAPRYKAR NUMBER.
 #include <stdio.h>
#include <conio.h>
void main()
{
    int kp=0,d1,d2,sq,n,div=10;
    printf("Enter the number");
    scanf("%d",&n);
    sq=n*n;
    while(div>0)
    {
        d1=sq%div;
        d2=sq/div;
        if(d1+d2==n)
        {
            kp=1;
            }
        if(d2<=9)
        {
            break;
            }
        div=div*10;
        }
        if(kp==1)
        printf("KAPRYKAR NUMBER");
        else
        printf("NOT KAPRYKAR NUMBER");
        }

WAP to print fibonacci series till n terms

WAP to print fibonacci series till n terms
Example: n=6
Output:0 1 1 2 3 5
#include <stdio.h>
#include <conio.h>
void main()
{
    int n,a=0,b=1,c=0;
    printf("Enter the number of terms");
    scanf("%d",&n);
    printf("%d %d ",a,b);
    for(int i=3;i<=n;i++)
    {
        c=a+b;
        printf("%d ",c);
        a=b;
        b=c;
        }
        }

WAP to enter no. of days and print the no of years,months and days

  • WAP to enter no. of days and print the no of years,months and days
#include <stdio.h>
#include <conio.h>
void main()
{
    int n,d,y,m;
    printf("Enter the number of day");
    scanf("%d",&n);
    y=n/365;
    d=n%365;
    m=d/30;
    d=d%30;
    printf("%d Year %d Month %d day",y,m,d);
    }

Saturday, 1 September 2012

  • WAP to fnd the possible combinaton.
Example: Enter a number :21
Output:1+2+3+4+5+6
            6+7+8
           10+11

#include <stdio.h>
#include <conio.h>
void main()
{
    int i,no,sum;
    printf("Enter a number");
    scanf("%d",&no);
    for(i=1;i<=no/2;i++)
    {
        sum=0;
        printf("\n");
        for(int j=i;j<no;j++)
        {
         sum=sum+j;
         if(sum==no)
         {
            for(int k=i;k<=j;k++)
            printf("%d +",k);
            break;
                }
            }
         }
         }

WAP to find the greatest of 3 numbers

  • WAP to find the greatest of 3 numbers
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b,c;
    clrscr();
    printf("Enter three numbers");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b&&a>c)
    printf("%d is greatest",a) ;
    else if(b>a&&b>c)
    printf("%d is greatest",b);
    else
    printf("%d is greater",c);
    getch();
   }

Swapping without 3rd Variable

  • WAP to swap two number without using a third variable.

//WAP to enter two number and swap them.
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b;
    printf("Enter first numbers");
    scanf("%d",&a);
    printf("Enter second numbers");
    scanf("%d",&b);
    a=a+b-(b=a);
    printf("The first number after swapping is %d and second number is %d",a,b);
    }

Introduction to My Blog

This is Rakesh...My Blog is based on coding of Program On any platform Such as C,C++ and Java. Please post your typical programs with answer or without for solution.