Tuesday, August 28, 2007

SUM OF ARRAY

WAP to sum of five elements of an array

void main ()

{

int no[5],i,sum;

clrscr ();

for (i=0;i<=4;i++)

{

printf ("Enter Element: ");

scanf ("%d",&no[i]);

}

sum=no[0]+no[1]+no[2]+no[3]+no[4];

printf ("\nSum of five Elements: %d",sum);

getch ();

}


PASSWORD VERIFICATION

WAP to print the detail of the programmer
if the given number is 464

void main ()

{

int pass;

clrscr();

do

{

printf ("Enter Password to see the detail of programmer:\n");

scanf ("%d",&pass);

}

while (pass!=464);

printf ("\nJagjeet Singh");

printf ("\nB.Sc. (I.T.)\nPunjab Technical University");

getch ();

}




PRINT STARS

WAP to print Stars on screen

void main ()

{

int i,j;

clrscr();

for (j=1;j<4;j++)

{

for (i=1;i<=5;i++)

{

printf ("*");

}

printf ("\n");

}

getch ();

}


SKIP 5 & 7

WAP to print series from 1 to 10 and skip 5 & 7


void main ()

{

int a;

clrscr ();

for (a=1;a<=10;a++)

{

if (a==5 || a==7)

continue;

printf ("%d\n",a);

}

getch ();

}



SERIES BREAK ON 5

WAP to print series from 1 to 10 and break on 5

void main ()

{

int a;

clrscr ();

for (a=1;a<=10;a++)

{

if (a==5)

break;

printf ("%d\n",a);

}

getch ();

}


ENTER & DISPLAY

WAP to print name and display on screen

void main ()

{

char name [15];

clrscr ();

printf ("Enter your name: ");

gets (name);

printf ("\nme is: %s",name);

getch ();

}


ASCII CODE - 0 TO 255

WAP to print ASCII code from 0 to 255

void main ()

{

int i=0,count=0;

clrscr ();

for(i=0;i<=255;i++)

{

if (count>24)

{count=0;getch();}

else

{printf("%d=%c\n",i,i);

count++;}

}

getch ();

}



Click on image to enlarge it


STRING LENGTH

WAP to find the length of any string

void main ()

{

char ch [20];

int l;

clrscr ();

printf ("Enter String: ");

gets (ch);

l=strlen(ch);

printf ("Length of string is %d",l);

getch ();

}


FIND STRING

WAP to find string within a string

void main ()

{

char *k="Borland International", *g, *p;

clrscr ();

printf ("Enter string to find: ");

gets (g);

p=strstr(k,g);

printf ("%s",p);

getch ();

}


UPPER, LOWER AND REVERSE

WAP to find length of string and show it in upper, lower and reverse order

void main ()

{

char str [20];

clrscr ();

printf ("Enter your name: ");

gets (str);

printf("\nLength is : %d",strlen(str));

printf("\nUpper is : %s",strupr(str));

printf("\nLower is : %s",strlwr(str));

printf("\nReverese is : %s",strrev(str));

getch ();

}



GOOD ELSE BAD

WAP to find if number=10 then Good else Bad

void main ()

{

int a;

clrscr ();

printf ("Enter any Number: ");

scanf ("%d",&a);

if (a==10)

goto g;

else

goto b;

g:

printf ("Good");

goto end;

b:

printf ("Bad");

goto end;

end:

getch ();

}


RECORDS ENTRY

WAP to enter records and also repeat the step if user wants to continue

void main ()

{

char nm [20],cls[10];

int rollno,m1,m2,m3,tm;

float per;

char ch;

clrscr ();

do

{

printf ("\nEnter Marks of Hindi: ");

scanf ("%d",&m1);

printf ("Enter Marks of Pbi : ");

scanf ("%d",&m2);

printf ("Enter Marks of Math : ");

scanf ("%d",&m3);

tm=m1+m2+m3;

per=(tm*100)/300;

printf ("\nTotal Marks are %d",tm);

printf ("\nPercentage is %.2f",per);

printf ("\nDo you want to continue Y/N: ");

fflush(stdin);

scanf ("%c",&ch);

}

while (ch=='y' || ch=='Y');

getch ();

}


GETCH ( ) FUNCTION

WAP to enter character by using getch ( ) function

#include

void main ()

{

char ch;

clrscr ();

printf ("Enter any character: ");

ch=getch();

printf ("You have pressed %c",ch);

getch ();

}


MATRIX 2 X 3

WAP to create double dimension array of 2x3 matrix and display its Elements


void main ()

{

int a[2][3],i,j;

clrscr ();

for (i=0;i<2;i++)

{

for (j=0;j<3;j++)

{

printf ("\nEnter element: ");

scanf ("%d",&a[i][j]);

}

}

for (i=0;i<2;i++)

{

for (j=0;j<3;j++)

{

printf ("%d\t",a[i][j]);

}

printf ("\n");

}

getch ();

}




NUMBER OF VOWELS

WAP to count number of vowels

void main ()

{

char s[20],vw=0,i;

clrscr();

printf ("Enter any string: ");

gets (s);

for (i=0;i<=strlen(s);i++)

{

switch (s[i])

{

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

vw++;

}

}

printf ("There are %d vowels in it",vw);

getch ();

}

CONCATENATE TWO STRINGS

WAP to concatenate two strings

void main ()

{

char *str,*str1;

clrscr ();

printf("Enter your name: ");

gets (str);

str1="jeet";

strcat(str,str1);

printf("\n %s",str);

getch ();

}



SWITCH CASE

WAP to find amount of given quantity of any company with 10% discount using switch case

void main()

{

int,ch qty;

long tb,dis,nb;

clrscr();

printf("1.BPL\n2.Onida\n3.Sony\n4.Samsung\n5.LG\n");

printf("\nEnter Your Choice: ");

fflush(stdin);

scanf("%d",&ch);

printf("Enter Qty: ");

scanf("%d",&qty);

switch(ch)

{

case 1:tb=(long)qty*10000;

printf("\nBPL is %ld",tb);

break;

case 2:tb=(long)qty*12000;

printf("\nOnida is %ld",tb);

break;

case 3:tb=(long)qty*11500;

printf("\nSony is %ld ",tb);

break;

case 4:tb=(long)qty*11000;

printf("\nSamsung is %ld ",tb);

break;

case 5:tb=(long)qty*13000;

printf("\nLG is %ld ",tb);

break;

Default:

printf("Wrong Choice...");

}

dis=(tb*10)/100;

nb=tb-dis;

printf("\nDiscount is %ld",dis);

printf("

\nNet bill is %ld",nb);

getch();

}


SIZE OF VARIABLE

WAP to find size of any variable

void main()

{

int a;

float b;

double c;

char ch;

long d;

char nm[10];

clrscr();

printf("\nInt size is \t:%d", sizeof (a));

printf("\nFloat size is \t:%d", sizeof (b));

printf("\nDouble size is \t:%d", sizeof (c));

printf("\nChar size is \t:%d", sizeof (ch));

printf("\nLong size is \t:%d", sizeof (d));

printf("\nString size is \t:%d", sizeof (nm));

getch ();

}


FACTORIAL NUMBER

WAP to find the factorial of the number (1x2x3x4)


void main ()

{

int fact=1,no;

clrscr();

printf ("Enter any number: ");

scanf ("%d",&no);

do

{

fact=fact*no;

no--;

}

while (no>0);

printf ("\nFactorial is %d",fact);

getch ();

}




PRINT SERIES (VARIABLE)

WAP to print series from start to end using do-while loop

void main ()

{

int a,b;

clrscr ();

printf ("Enter Start: ");

scanf ("%d",&a);

printf ("Enter End: ");

scanf ("%d",&b);

do

{

printf ("%d\n",a);

a++;

}

while (a<=b);

getch ();

}


PRINT NAME 10 TIMES

WAP to print any name on screen 10 times

void main ()

{

int a=1;

clrscr();

do

{

printf ("Jagjeet\n");

a++;

}

while (a<=10);

getch ();

}


PRIME NUMBER

WAP to find that number is prime or not (7,11,13,17,19 etc.)


void main ()

{

int no,i=2;

clrscr ();

printf ("Enter Number: ");

scanf ("%d",&no);

while (i<=no)

{

if (no%i==0)

break;

i++;

}

if (i==no)

printf ("Number is Prime");

else

printf ("Number is not Prime");

getch ();

}





SQUARE & CUBE

WAP to print series from 1 to 10 & find its square and cube


void main ()

{

int a=1,sqr=0,cube=0;

clrscr ();

while (a<=10)

{

sqr=pow(a,2);

cube=pow(a,3);

printf ("%d\t %d\t %d\n",a,sqr,cube);

a++;

}

getch ();

}



FABBONIC SERIES

WAP to print fabbonic series from 1 to 55

void main ()

{

int a,b,c;

clrscr ();

a=0;b=1;c=1;

printf ("%d\n%d",a,b);

while (c<55)

{

c=a+b;

printf ("\n%d",c);

a=b;

b=c;

}

getch ();

}


TABLE OF 5

WAP to print table of 5

void main ()

{

int a,tab;

clrscr ();

a=1,tab=0;

while (a<=10)

{

tab=5*a;

a++;

printf ("%d\n",tab);

}

getch ();

}






NUMBERS DIVIDED BY 7


WAP to print numbers from 1-50 which are divided by 7

void main ()

{

int a;

clrscr ();

a=1;

while (a<=50)

{

if (a%7==0)

printf ("%d\n",a);

a++;

}

getch ();

}


ADD ENTERED DIGITS

WAP to add entered three digits

void main ()

{

int no,r,res;

clrscr ();

printf ("Enter any value: ");

scanf ("%d",&no);

r=res=0;

while (no>0)

{

r=no%10;

no=no/10;

res=(res+r);

}

printf ("Sum is %d",res);

getch ();

}


REVERSE NUMBER

WAP to Reverse of any number using while loop

void main ()

{

int no,r,res;

clrscr ();

printf ("Enter any value: ");

scanf ("%d",&no);

r=res=0;

while (no>0)

{

r=no%10;

no=no/10;

res=(res*10)+r;

}

printf ("\nReverse is %d",res);

getch ();

}


ODD SERIES 20 TO 1

WAP to print Even & Odd numbers from 20 to 1

void main ()

{

int a;

clrscr ();

a=20;

while (a>=1)

{

if (a%2==0)

printf ("%d\t",a);

else

printf ("%d\n",a);

a--;

}

getch ();

}

SERIES 20 TO 1

WAP to print series from 20 to 1

#include

void main ()

{

int a;

clrscr ();

a=20;

while (a>=1)

{

printf ("\n%d",a);

a--;

}

getch ();

}



ODD SERIES

WAP to print Odd numbers from 1 to 20

void main ()

{

int a;

clrscr ();

a=1;

while (a<=20)

{

if (a%2==1)

printf ("\n%d",a);

a++;

}

getch ();

}


PALANDROM NUMBER

WAP to find that number is palandrom or not (121=121)

#include

void main ()

{

int no,r,res,temp=0;

clrscr ();

printf ("Enter Number: ");

scanf ("%d",&no);

r=res=0;

temp=no;

while (no>0)

{

r=no%10;

no=no/10;

res=(res*10)+r;

}

if (temp==res)

printf("Number is Palandrom");

else

printf("Number is not Palandrom");

getch ();

}


QUARDRATIC EQUATION

WAP to find out Quardratic Equation (d=b2-4ac)

void main ()

{

int a,b,c,d;

clrscr ();

printf ("Enter A: ");

scanf ("%d",&a);

printf ("Enter B: ");

scanf ("%d",&b);

printf ("Enter C: ");

scanf ("%d",&c);

d= (b*b)-(4*a*c);

printf ("\nAnswer is %d",d);

getch ();

}


LEAP YEAR

WAP to find out Year is leap or not (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the Year: ");

scanf("%d",&a);

if (a%4==0)

{

printf ("\nYear is Leap");

}

else

{

printf("\nYear is not Leap");

}

getch ();

}


SWAP NUMBERS

WAP to SWAP the three digit number

void main ()

{

int b,r,n,r1,r2;

clrscr ();

printf ("Enter the Value: ");

scanf ("%d",&n);

r=n%10;

n=n/10;

r1=n%10;

n=n/10;

r2=n%10;

n=n/10;

b=(r*100)*(r2*10)+(r2);

printf ("%d%d%d",r,r1,r2);

getch ();

}


INCREMENTAL / DECREMENTAL

WAP to add 1 & subtract 1 from value of a & b

(Incremental & Decremental Operators)

void main ()

{

int a,b;

clrscr();

printf ("Enter A: ");

scanf ("%d",&a);

printf ("Enter B: ");

scanf ("%d",&b);

a++;

b--;

printf ("\nA is %d",a);

printf ("\nB is %d",b);

getch ();

}


POSITIVE / NEGATIVE

WAP to find out Positive or Negative (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

if (a>=0)

{

printf ("Number is Positive");

}

else

{

printf("Number is Negative");

}

getch ();

}


EVEN OR ODD

WAP to find out Even or Odd number (IF-ELSE)

void main ()

{

int a;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

if (a%2==0)

{

printf ("\nNumber is Even");

}

else

{

printf("\nNumber is Odd");

}

getch ();

}




TOTAL SALARY

WAP to find out TOTAL SALARY with (IF-ELSE)

void main ()

{

long int sal,hra,ta,ts;

clrscr ();

printf ("Enter Salary: ");

scanf("%ld",&sal);

if (sal>=5000)

{

hra=sal*.10;

ta=sal*.07;

}

else

{

hra=sal*.08;

ta=sal*.05;

}

ts=sal+hra+ta;

printf ("\n\nTotal Salary is Rs.%ld", ts);

getch ();

}


TOTAL BILL/ DISCOUNT A

WAP to find out Total Bill with discount according to conditions (Ternary Operators)

void main ()

{

int b,dis,n;

clrscr ();

printf ("Enter Bill: ");

scanf ("%d",&b);

dis=(b<500)?(b*.10):(b>=500 &&amp; b<1000)?(b*.15):(b>=1000 && b<=2000)?(b*.20):(b*.25);

n=b-dis;

printf ("Net Bill is %d",n);

getch();

}

BIGGER & EQUAL

WAP to find out Bigger & Equal number from three numbers
(Ternary Operators)

void main ()

{

int a,b,c;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

printf ("Enter the value of C: ");

scanf ("%d",&c);

(a>b && a>c)?printf("A is Big"):(b>a && b>c)?printf("B is Big"):(a==b && b==c)?printf("All are Eqaul"):printf("C is Big");

getch ();

}

BIGGER NUMBER 2

WAP to find out Bigger number from two numbers
(Ternary Operators)

void main ()

{

int a,b;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

(a>b)? printf ("A is Big"):printf("B is Big");

getch ();

}


BIGGER NUMBER 1

wap to find out bigger number (if-else)

void main ()

{

int a,b;

clrscr ();

printf ("Enter the value of A: ");

scanf("%d",&a);

printf ("Enter the value of B: ");

scanf ("%d",&b);

if (a>b)

{

printf ("A is Greater");

}

else

{

printf("B is Greater");

}

getch ();

}