Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
×
0 of .
Results for:
P. 1
Data Structure Using C

# Data Structure Using C

Ratings: 0|Views: 1,927|Likes:

Published by: dancobbinah2760 on Dec 21, 2009

### Availability:

Read on Scribd mobile: iPhone, iPad and Android.
See More
See less

02/06/2013

pdf

text

original

[Q001] Write a program (W.A.P.) in C to SWAP the contents of 3 variables withoutusing the temporary (or extra) variables./* Swapping 3 numbers without using extra variable */#include< stdio.h >#include< conio.h >void Swap(int *a,int *b,int *c){*a = *a + *b + *c;*b = *a - (*b + *c);*c = *a - (*b + *c);*a = *a - (*b + *c);}int main(){int x=1,y=2,z=3;clrscr(); printf("BEFORE SWAPPING : %d %d %d\n",x,y,z);Swap(&x,&y,&z); printf("AFTER SWAPPING : %d %d %d",x,y,z);return(0);} /* End of Main */[Q002] W.A.P. in C to find the Fifth root of the sum of the squares of the first 100ODDnumbers only./* To find the Fifth root of the sum of the squares of the first 100 ODD numbersONLY */#include< stdio.h >#include< conio.h >#include< math.h >int main(void){long i,oddnum=1,sqrnum,sum=0;for (i=1; i<=100; i++){sqrnum=oddnum * oddnum; // Square the ODD number sum+=sqrnum; // Add Square value to the sumoddnum+=2; // Get the next ODD number } printf("\nThe result is : %ld,%.2f",sum,pow((double)sum,(1.0/5.0)));return(0);} /* End of Main */

[Q003] W.A.P. in C to multiply any two numbers without using * (asterisk)[Hint : Use BITWISE OPERATORS]/* Multiplication of two numbers using BITWISE OPERATORS ONLY */#include< stdio.h >int main(){long int i,n,mul,mul2,count,temp,a,b,sum,carry,res,tot; printf("\nEnter any 2 numbers : ");scanf("%ld %ld",&mul,&n);mul2=temp=mul;for (i=2; i<=n; i++){temp=mul;count=32;res=1;tot=sum=carry=0;while (count--){a=temp & 0x1; b=mul2 & 0x1;if ((a^b==1) && (carry==1)){sum=(a^b)^carry;carry=(a^b)&carry;}else{sum=a^b|carry;carry=a&b;}temp=temp>>1;mul2=mul2>>1;tot+=res*sum;res=res*2;}mul2=tot;} printf("\n%3ld * %3ld = %3ld",mul,i-1,tot);getch();return(0);} /* End of Main */

[Q004] W.A.P. in C to check whether given number x is equal to the value 2 POWER ior something, where i>=0 using BITWISE operators ONLY. [Hint : Check whether thegiven number x is equal to the value 2 POWER i or something using BITWISE operatorsONLY]/* Check whether the given number x is equal to the value 2 power i or not usingBITWISE operators ONLY */#include< stdio.h >#include< conio.h >int main(void){long x; printf("Enter a number : ");scanf("%ld",&x);if ((x & 0x1) == 0x0) // Checking the Least significant bit printf("The given number %ld is EQUAL to the value 2 POWER something",x);else printf("The given number %ld is NOT EQUAL to the value 2 POWER something",x);getch();return(0);} /* End of Main */[Q005] W.A.P. in C to maintain 2 STACKS within a SINGLE ARRAY and the values of onestack should not overwrite the values of another stack./* Maintaining TWO STACKS within a SINGLE ARRAY */#include< stdio.h >#include< conio.h >#define MAX 10int stack[MAX],top1,top2;void init(){top1=-1;top2=10;}void Push1(int item){stack[++top1]=item;}void Push2(int item){stack[--top2]=item;}int Pop1()

## Activity (58)

### Showing

AllMost RecentReviewsAll NotesLikes
You've already reviewed this. Edit your review.
1 hundred reads|almost 4 years ago