-
-
Save swaaz/95149c87a01c1be3c17a258349b4b229 to your computer and use it in GitHub Desktop.
basic programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
int s[100],top=-1,max,i; | |
int push(); | |
int pop(); | |
int display(); | |
int palindrome(); | |
int main() | |
{ | |
int o; | |
printf("Enter the max size\n"); | |
scanf("%d",&max); | |
while (1) | |
{ | |
printf("\n1.push\n2.pop\n3.display\n4.palindrome\n5.exit\n"); | |
printf("enter choice\n"); | |
scanf("%d",&o); | |
switch(o) | |
{ | |
case 1: push(); | |
break; | |
case 2: pop(); | |
break; | |
case 3: display(); | |
break; | |
case 4: palindrome(); | |
break; | |
case 5: exit(0); | |
default: printf("invalid option\n"); | |
} | |
} | |
return 0; | |
} | |
int push() | |
{ | |
int x; | |
if(top==max-1) | |
{ | |
printf("overflow\n"); | |
} | |
else | |
{ | |
printf(" enter element\n"); | |
scanf("%d",&x); | |
s[++top]=x; | |
} | |
return 0; | |
} | |
int pop() | |
{ | |
int x; | |
if(top==-1) | |
{ | |
printf("underflow\n"); | |
} | |
else | |
{ | |
x=s[top--]; | |
printf("popped elements:%d\t",x); | |
} | |
return 0; | |
} | |
int display() | |
{ | |
if(top==0) | |
{ | |
printf("stack is underflow\n"); | |
return 0; | |
} | |
else | |
{ | |
for(i=0;i<=top;i++) | |
{ | |
printf("%d\t",s[i]); | |
} | |
} | |
return 0; | |
} | |
int palindrome() | |
{ | |
int flag=0; | |
for(i=0;i>(top/2)+1;i++) | |
{ | |
if(s[i]!=s[top-i]) flag=1; | |
} | |
if(flag) printf("Not palindrome\n"); | |
else printf("plaindrome\n"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ int a=7,b=2; | |
// printf("enter two number !\n"); | |
//scanf("%d%d",&a,&b); | |
printf("%d",a/b); | |
printf("%d\n",(float)a/b); | |
printf("%d\n",(float)a/(float)b); | |
printf("%d\n",a/(float)b); | |
printf("%f\n",a/b); | |
printf("%f\n",(float)(a/b)); | |
printf("%f\n",(float) a/b); | |
printf("%f\n",(float)a/(float)b); | |
printf("%f\n",a/(float)b); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Program to compare 2 number without using relational operators*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ int a,b; | |
printf("Enter two numbers\n"); | |
scanf("%d%d",&a,&b); | |
if(a^b) printf(" not equal"); | |
else printf(" equal"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment