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