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