Thursday, September 30, 2010

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

}

Wednesday, September 29, 2010

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

}

Tuesday, September 28, 2010

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

}

Monday, September 27, 2010

WAP to find out total marks of three subjects

void main ()

{

int m1,m2,m3,tm;

clrscr ();

printf ("Enter M1: ");

scanf ("%d",&m1);

printf ("Enter M2: ");

scanf ("%d",&m2);

printf ("Enter M3: ");

scanf ("%d",&m3);

tm=m1+m2+m3;

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

getch ();

}

Sunday, September 26, 2010

WAP to find out total marks & Percentage of three subjects

void main ()

{

int m1,m2,m3;

float tm,per;

clrscr ();

printf ("Enter M1: ");

scanf ("%d",&m1);

printf ("Enter M2: ");

scanf ("%d",&m2);

printf ("Enter M3: ");

scanf ("%d",&m3);

tm=m1+m2+m3;

per=(tm/300*100);

printf ("\nTotal Marks are %.2f",tm);

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

getch ();

}

Saturday, September 25, 2010

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 && b<1000)?(b*.15):(b>=1000 && b<=2000)?(b*.20):(b*.25);

n=b-dis;

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

getch();

}

Friday, September 24, 2010

WAP to find out Square root of any number


#include

#include

void main ()

{

int no, a;

clrscr ();

printf ("Enter Number : ");

scanf ("%d",&no);

a=sqrt(no);

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

getch ();

}

Thursday, September 23, 2010

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

}

Wednesday, September 22, 2010

WAP to find out power of any number


#include

#include

void main ()

{

double no,r,res;

clrscr ();

printf ("Enter Number : ");

scanf ("%lf",&no);

printf ("Enter raised : ");

scanf ("%lf",&r);

res=pow(no,r);

printf ("\nResult is %.2lf", res);

getch ();

}

Tuesday, September 21, 2010

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

}

Monday, September 20, 2010

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

}

Sunday, September 19, 2010

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

}

Saturday, September 18, 2010

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

}

Friday, September 17, 2010

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

}

Thursday, September 16, 2010

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

}

Wednesday, September 15, 2010

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

}

Tuesday, September 14, 2010

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

}


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

}

Monday, September 13, 2010

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

}

Sunday, September 12, 2010

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

}

Saturday, September 11, 2010

CELCIUS TO FAHRENHEIT

WAP to Convert CELCIUS to fahrenheit

void main ()

{

float c,f;

clrscr ();

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

scanf ("%f",&c);

f=(float) 9/5*c+32;

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

getch ();

}

Friday, September 10, 2010

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

}

Thursday, September 9, 2010

ADD TWO VARIABLES

WAP to add two variables

#include

void main ()

{

int a,b,c;

clrscr();

printf ("Enter A: ");

scanf ("%d",&a);

printf ("Enter B: ");

scanf ("%d",&b);

c=a+b;

printf ("\nSum is %d",c);

getch ();

}

Wednesday, September 8, 2010

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

}

Tuesday, September 7, 2010

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

}

Monday, September 6, 2010

Treesort - string array

#include "stdio.h"
#include "string.h"
#include "stdlib.h"

struct tnode
{
char *str;
struct tnode *left;
struct tnode *right;
};

void insert(struct tnode **p, char *value);
void print(struct tnode *root);

int main(void)
{
char line[1024];
struct tnode *root;

root = NULL;
while((fgets(line, 1024, stdin)) != NULL)
insert(&root, line);

print(root);
return 0;
}

/* call by reference .. ! */
void insert(struct tnode **p, char *value)
{
if(!*p) {
*p = (struct tnode *)malloc(sizeof(struct tnode));
(*p)->left = (*p)->right = NULL;
(*p)->str = strdup(value);
return;
}

if(strcmp(value, (*p)->str) < 0)
insert(&(*p)->left, value);
else
insert(&(*p)->right, value);
}

/* inorder binary tree print ... */
void print(struct tnode *root)
{
if(root != NULL)
{
print(root->left);
printf("%s", root->str);
print(root->right);
}
}

Sunday, September 5, 2010

This program calculates an average of the numbers entered

#include
int Average(int i);

int main()
{
int num;
do
{
printf("Enter numbers.\n");
scanf("%d",&num);
if(num != -1)
printf("The average is %d", Average(num));
printf("\n");

}while(num>-1);

return 0;
}

int Average(int i)
{
static int sum = 0, count = 0;
sum = sum + i;
count++;
return sum / count;
}

Saturday, September 4, 2010

String array Qsort

#include
#include
#include

void sortstrarr(void *array, unsigned n);
static int cmpr(const void *a, const void *b);

int main(void)
{
char line[1024];
char *line_array[1024];
int i = 0;
int j = 0;

while((fgets(line, 1024, stdin)) != NULL)
if(i < 1024)
line_array[i++] = strdup(line);
else
break;

sortstrarr(line_array, i);

while(j < i)
printf("%s", line_array[j++]);

return 0;
}

static int cmpr(const void *a, const void *b)
{
return strcmp(*(char **)a, *(char **)b);
}

void sortstrarr(void *array, unsigned n)
{
qsort(array, n, sizeof(char *), cmpr);
}

Friday, September 3, 2010

Square Root of a number by using simple calculations

#include
#include
main()
{
float a,b,e=0.00001,p,k;
clrscr();
textcolor(GREEN);
do {
printf("*******************************************************");
printf(" PROGRAM TO FIND SQUARE ROOT OF A NUMBERxDB
");
printf("*********************************************************");
cprintf("ENTER A NUMBER(-1 to Quit) :");
scanf("%f",&k);

a=k;p=a*a;
while(p-k>=e)
{
b=(a+(k/a))/2;
a=b;
p=a*a;
}
printf("SQUARE ROOT IS = %f",a);
getch();
clrscr();
}
while(k!=-1);
getch();
}

Thursday, September 2, 2010

Shsort, shell sort array

#include "stdio.h"

#define MAXARRAY 10

void shellsort(int a[], int total, int index);

int main(void)
{
int array[MAXARRAY] = {0};
int i = 0;

/* load some random values into the array */
for(i = 0; i < MAXARRAY; i++)
array[i] = rand() % 100;

/* print the original array */
printf("Before shellsort: ");
for(i = 0; i < MAXARRAY; i++)
{
printf(" %d ", array[i]);
}
printf("\n");

shellsort(array, MAXARRAY, 1);

/* print the `shellsorted' array */
printf("After shellsort: ");
for(i = 0; i < MAXARRAY; i++)
{
printf(" %d ", array[i]);
}
printf("\n");

return 0;
}

void shellsort(int a[], int total, int index)
{
int i = 0;
int j = 0;
int k = 0;
int l = 0;

for(k = 0; k < index; k++)
{
for(i = k; i < total; i += index)
{
l = a[i];
for(j = (i - index); j >= 0; j -= index)
{
if(a[j] > l)
a[j + index] = a[j];
else
break;
}
a[j + index] = l;
}
}

return;
}

Wednesday, September 1, 2010

Selection sort linked list

#include "stdio.h"
#include "stdlib.h"

#define MAX 10

struct lnode
{
int data;
struct lnode *next;
} *head, *visit;

/* add a new entry to the linked list */
void llist_add(struct lnode **q, int num);
/* preform a selection sort on the linked list */
void llist_selection_sort(void);
/* print the entire linked list */
void llist_print(void);

int main(void)
{
/* linked list */
struct lnode *newnode = NULL;
int i = 0; /* a general counter */

/* load some random values into the linked list */
for(i = 0; i < MAX; i++) {
llist_add(&newnode, (rand() % 100));
}

head = newnode;
printf("Before selection sort:\n");
llist_print();
printf("After selection sort:\n");
llist_selection_sort();
llist_print();

return 0;
}

/* adds a node at the end of a linked list */
void llist_add(struct lnode **q, int num)
{
struct lnode *temp;

temp = *q;

/* if the list is empty, create first node */
if(*q == NULL) {
*q = malloc(sizeof(struct lnode));
temp = *q;
} else {
/* go to last node */
while(temp->next != NULL)
temp = temp->next;

/* add node at the end */
temp->next = malloc(sizeof(struct lnode));
temp = temp->next;
}

/* assign data to the last node */
temp->data = num;
temp->next = NULL;
}

/* print the entire linked list */
void llist_print(void)
{
visit = head;

/* traverse the entire linked list */
while(visit != NULL)
{
printf("%d ", visit->data);
visit = visit->next;
}
printf("\n");
}

void llist_selection_sort(void)
{
struct lnode *a = NULL;
struct lnode *b = NULL;
struct lnode *c = NULL;
struct lnode *d = NULL;
struct lnode *tmp = NULL;

a = c = head;
while(a->next != NULL)
{
d = b = a->next;
while(b != NULL) {
if(a->data > b->data)
{
/* neighboring linked list node */
if(a->next == b)
{
if(a == head)
{
a->next = b->next;
b->next = a;
tmp = a;
a = b;
b = tmp;
head = a;
c = a;
d = b;
b = b->next;
} else {
a->next = b->next;
b->next = a;
c->next = b;
tmp = a;
a = b;
b = tmp;
d = b;
b = b->next;
}
} else
{
if(a == head)
{
tmp = b->next;
b->next = a->next;
a->next = tmp;
d->next = a;
tmp = a;
a = b;
b = tmp;
d = b;
b = b->next;
head = a;
} else
{
tmp = b->next;
b->next = a->next;
a->next = tmp;
c->next = b;
d->next = a;
tmp = a;
a = b;
b = tmp;
d = b;
b = b->next;
}
}
} else
{
d = b;
b = b->next;
}
}
c = a;
a = a->next;
}
}
AddThis

Related Posts Plugin for WordPress, Blogger...