├── README.md ├── HELLO1.C ├── 1. SUM.C ├── ODD_EVEN.C ├── ADDITION.C ├── GROSS_SALARY.C ├── AREA_RECTANGLE.C ├── 2. CIRCLE.C ├── SIMPLE_INTEREST.C ├── PATTERN1.C ├── PATTERN_2.C ├── palindrome_num.cpp ├── DEL_FROM_ARRAY.C ├── REM_DUPLICATE.C ├── REVERSE_STRING.C ├── MERGE_S_ARRAY.C ├── EVALUATE_POSTFIX.C ├── OPERATION_ON_MATRIX.C ├── INFIX_TO_PREFIX └── INFIX_TO_POSTFIX.C /README.md: -------------------------------------------------------------------------------- 1 | # C 2 | ### Beginner to Advance -------------------------------------------------------------------------------- /HELLO1.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | printf("hello world"); 6 | getch(); 7 | } -------------------------------------------------------------------------------- /1. SUM.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int num1, num2; 6 | clrscr(); 7 | printf("Enter Two Integer numbers :: "); 8 | scanf("%d %d", &num1, &num2); 9 | printf("\nSum = %d", num1+num2); 10 | getch(); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /ODD_EVEN.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int x; 6 | clrscr(); 7 | printf("\n ENTER THE NUMBER :: "); 8 | scanf("%d",&x); 9 | if (x%2==0) 10 | { 11 | printf("\n ENTERED NUMBER IS EVEN"); 12 | } 13 | else 14 | { 15 | printf("\n ENTERED NUMBER IS ODD"); 16 | } 17 | getch(); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /ADDITION.C: -------------------------------------------------------------------------------- 1 | /* ADDITION OF TWO NUMBERS */ 2 | #include 3 | #include 4 | void main() 5 | { 6 | int num1,num2,add; //VARIABLE DECLARATION 7 | clrscr(); 8 | printf("Enter the two numbers :"); 9 | scanf("%d%d",&a,&b); //INPUT 10 | add=a+b; //ADDING 11 | printf("Sum of given numbers = %d",add); //OUTPUT 12 | getch(); 13 | } -------------------------------------------------------------------------------- /GROSS_SALARY.C: -------------------------------------------------------------------------------- 1 | // Program to find Gross Salary. 2 | #include 3 | #include 4 | void main() 5 | { 6 | float gs,hra,ta,da; 7 | int bs; 8 | clrscr(); 9 | printf("\n Enter your Salary:"); 10 | scanf("%d",&bs); 11 | hra = 0.05 * bs; 12 | da = 0.02 * bs; 13 | ta = 0.01 * bs; 14 | gs = hra + da + ta + bs; 15 | printf("\n Your Gross Salary is %.2f",gs); 16 | getch(); 17 | } -------------------------------------------------------------------------------- /AREA_RECTANGLE.C: -------------------------------------------------------------------------------- 1 | // Program to find the area of the rectangle. 2 | 3 | #include 4 | #include 5 | void main() 6 | { 7 | int l,b,ar; 8 | clrscr(); 9 | printf("\nEnter the Length of the Rectangle:"); 10 | scanf("%d",&l); 11 | printf("\nEnter the Breadth of the Rectangle:"); 12 | scanf("%d",&b); 13 | ar=l*b; 14 | printf("\nArea of the Rectangle is %d",ar); 15 | getch(); 16 | } -------------------------------------------------------------------------------- /2. CIRCLE.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | float radius, area, circumference; 6 | const float pi = 3.14; 7 | clrscr(); 8 | printf("Enter Radius of Circle :: "); 9 | scanf("%f", &radius); 10 | area = pi * radius * radius; 11 | circumference = 2 * pi * radius; 12 | printf("\nArea = %f\nCircumference = %f", area, circumference); 13 | getch(); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /SIMPLE_INTEREST.C: -------------------------------------------------------------------------------- 1 | // Program to calculate Simple Interest. 2 | 3 | #include 4 | #include 5 | void main() 6 | { 7 | float p,r,t,si; 8 | clrscr(); 9 | printf("ENTER PRINCIPLE AMOUNT :: "); 10 | scanf("%f",&p); 11 | printf("ENTER RATE :: "); 12 | scanf("%f",&r); 13 | printf("ENTER TIME :: "); 14 | scanf("%f",&t); 15 | si=(p*r*t)/100; 16 | printf("\n Simple Interest is %.2f",si); 17 | getch(); 18 | } -------------------------------------------------------------------------------- /PATTERN1.C: -------------------------------------------------------------------------------- 1 | /* OUTPUT PATTERN 2 | * 3 | * * 4 | * * * 5 | * * * * */ 6 | 7 | #include 8 | #include 9 | void main() 10 | { 11 | int x,i,j; 12 | clrscr(); 13 | printf("HOW MANY LINES STARS (*) SHOULD BE PRINTED? :: "); 14 | scanf("%d",&x); 15 | printf("\n\t\tOUTPUT\n\n"); 16 | for (i=0;i<=x;i++) 17 | { 18 | for (j=0;j<=i;j++) 19 | { 20 | printf("* "); 21 | } 22 | printf("\n"); 23 | } 24 | getch(); 25 | } 26 | -------------------------------------------------------------------------------- /PATTERN_2.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int row, c, n, temp; //VARAIBLE DECLARATION 7 | clrscr(); 8 | printf("ENTER NUMBER OF ROWS IN PYRAMID :: "); 9 | scanf("%d",&n); 10 | 11 | temp = n; 12 | 13 | for ( row = 1 ; row <= n ; row++ ) 14 | { 15 | for ( c = 1 ; c < temp ; c++ ) 16 | printf(" "); 17 | 18 | temp--; 19 | 20 | for ( c = 1 ; c <= (2*row - 1) ; c++ ) 21 | printf("*"); 22 | 23 | printf("\n"); 24 | } 25 | 26 | getch(); 27 | } -------------------------------------------------------------------------------- /palindrome_num.cpp: -------------------------------------------------------------------------------- 1 | // *** Program to check if the given number is a palindrome of not *** 2 | #include 3 | int main() 4 | { 5 | int n,s=0,m; 6 | scanf("%d",&n); //Enter the number to be checked 7 | m=n; 8 | while(n!=0) //loop to reverse the number 9 | { 10 | s=(s*10)+(n%10); //incrementing s by 1 digit and adding the last digit of n 11 | n=n/10; //reducing n by one digit(from right) 12 | } 13 | if(m==s) 14 | printf("\nPalindrome"); 15 | else 16 | printf("\n Not a palindrome "); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /DEL_FROM_ARRAY.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | void main() 5 | { int a[50],n,loc,num,i; 6 | clrscr(); 7 | printf("\nEnter the limit of array="); 8 | scanf("%d",&n); 9 | printf("\nEnter the elements of array="); 10 | for(i=0;i 2 | #include 3 | void main() 4 | { 5 | int i,n,j,k,a[10]; 6 | clrscr(); 7 | printf("\nProgrm to Remove Duplicate Values\n"); 8 | printf("\nEnter Number of Elements in Array: "); 9 | scan f("%d",&n); 10 | printf("\nEnter Elements of Array:\n"); 11 | for(i=0;i 2 | #include 3 | #include 4 | 5 | char stack[20]; 6 | int top=-1; 7 | 8 | void push(char); 9 | char pop(); 10 | 11 | void main() 12 | { 13 | char str[20],ch; 14 | int l,i; 15 | clrscr(); 16 | printf("Welcome to string reverse program\n"); 17 | printf("\nEnter string:"); 18 | gets(str); 19 | l=strlen(str); 20 | for(i=0;i 2 | #include 3 | void main() 4 | { int a[20],b[20],c[20],i=0,j=0,k=0,m,n; 5 | clrscr(); 6 | printf("\nEnter the number of elements for 1st array="); 7 | scanf("%d",&m); 8 | printf("\nEnter the elements for 1st array="); 9 | for(i=0;i 3 | #include 4 | #include 5 | 6 | void evaluate(); 7 | void push(float f); 8 | float pop(); 9 | 10 | char q[20]; 11 | float stack[20]; 12 | int top=-1; 13 | 14 | void main() 15 | { 16 | clrscr(); 17 | printf("\nWelcome To Program Of Evaluate Postfix Expression By\n"); 18 | printf("\nEnter Postfix Expression: "); 19 | gets(q); 20 | evaluate(); 21 | getch(); 22 | } 23 | 24 | void evaluate() 25 | { 26 | float a,b,value[20]; 27 | int i; 28 | for(i=0;q[i]!='\0';i++) 29 | { 30 | if(q[i]>=65 && q[i]<=92) 31 | { 32 | fflush(stdin); 33 | printf("\nEnter The Value Of %c: ",q[i]); 34 | scanf("%f",&value[i]); 35 | } 36 | } 37 | for(i=0;i=65 && q[i]<=92) 40 | { 41 | push(value[i]); 42 | } 43 | else 44 | { 45 | b=pop(); /*top element*/ 46 | a=pop(); /*second top*/ 47 | if(q[i]=='^') 48 | push(pow(a,b)); 49 | else if(q[i]=='/') 50 | push(a/b); 51 | else if(q[i]=='*') 52 | push(a*b); 53 | else if(q[i]=='+') 54 | push(a+b); 55 | else if(q[i]=='-') 56 | push(a-b); 57 | } 58 | } 59 | printf("\nAnswer After Solvong Postfix Expression %f",stack[top]); 60 | } 61 | 62 | void push(float f) 63 | { 64 | top++; 65 | stack[top]=f; 66 | } 67 | 68 | float pop() 69 | { 70 | return(stack[top--]); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /OPERATION_ON_MATRIX.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void main() 4 | { 5 | int i,j,k,ch,r,c,x[5][5],y[5][5],z[5][5]; 6 | clrscr(); 7 | 8 | printf("\nWelcome To Matrix Program"); 9 | printf("\n\nEnter Number of Rows: "); 10 | scanf("%d",&r); 11 | printf("Enter Number of Columns: "); 12 | scanf("%d",&c); 13 | printf("\nEnter First Matrix: \n"); 14 | for(i=0;i 2 | #include 3 | #include 4 | #define MAX 50 5 | 6 | char infix[MAX]; 7 | char prefix[MAX]; 8 | int stack[MAX]; 9 | int top=0; 10 | 11 | void intop(); 12 | int pop(); 13 | int prec(int); 14 | void push(int); 15 | 16 | void main() 17 | { 18 | clrscr(); 19 | printf("\nWelcome To Infix To Prefix Program By Ankit Verma\n"); 20 | printf("\nEnter Infix Expression: "); 21 | gets(infix); 22 | fflush(stdin); 23 | strrev(infix); 24 | intop(); 25 | getch(); 26 | } 27 | 28 | void push(int symbol) 29 | { 30 | if(top>MAX) 31 | { 32 | printf("\nStack Overflow !!!"); 33 | getch(); 34 | exit(1); 35 | } 36 | else 37 | { 38 | top=top+1; 39 | stack[top]=symbol; 40 | } 41 | } 42 | 43 | int pop() 44 | { 45 | if(top==0) 46 | { 47 | printf("\nStack Empty !!!"); 48 | getch(); 49 | exit(2); 50 | } 51 | else 52 | return(stack[top--]); 53 | return 0; 54 | } 55 | 56 | int prec(int symbol) 57 | { 58 | switch(symbol) 59 | { 60 | case '(': 61 | return 0; 62 | case '+': 63 | case '-': 64 | return 1; 65 | case '/': 66 | case '*': 67 | return 2; 68 | case '^': 69 | return 3; 70 | } 71 | return 0; 72 | } 73 | 74 | void intop() 75 | { 76 | int i,p=0,pre,len,next; 77 | stack[top]='#'; 78 | len=strlen(infix); 79 | infix[len]='#'; 80 | for(i=0;infix[i]!='#';i++) 81 | { 82 | switch(infix[i]) 83 | { 84 | case ')': 85 | push(infix[i]); 86 | break; 87 | case '(': 88 | while((next=pop())!=')') 89 | prefix[p++]=next; 90 | break; 91 | case '+': 92 | case '*': 93 | case '/': 94 | case '-': 95 | case '^': 96 | pre=prec(infix[i]); 97 | while(stack[top]!='#'&&pre<=prec(stack[top])) 98 | { 99 | prefix[p++]=pop(); 100 | } 101 | push(infix[i]); 102 | break; 103 | default: 104 | prefix[p++]=infix[i]; 105 | } 106 | } 107 | while(stack[top]!='#') 108 | prefix[p++]=pop(); 109 | prefix[p]='\0'; 110 | strrev(prefix); 111 | printf("\nAfter Converting Infix To Prefix Expression: "); 112 | puts(prefix); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /INFIX_TO_POSTFIX.C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 50 4 | 5 | char stack[50]; 6 | int top=-1; 7 | 8 | void in_to_post(char infix[]); 9 | void push(char); 10 | char pop(); 11 | 12 | void main() 13 | { 14 | char infix[25]; 15 | clrscr(); 16 | printf("\nWelcome To Infix To Postfix Program\n"); 17 | printf("\nEnter Infix Expression: "); 18 | gets(infix); 19 | in_to_post(infix); 20 | getch(); 21 | } 22 | 23 | void push(char symb) 24 | { 25 | if(top>=49) 26 | { 27 | printf("\nStack Overflow !!!"); 28 | getch(); 29 | return; 30 | } 31 | else 32 | { 33 | top=top+1; 34 | stack[top]=symb; 35 | } 36 | } 37 | 38 | char pop() 39 | { 40 | char item; 41 | if(top==-1) 42 | { 43 | printf("\nStack Empty !!!"); 44 | getch(); 45 | return (0); 46 | } 47 | else 48 | { 49 | item=stack[top]; 50 | top--; 51 | } 52 | return item; } 53 | 54 | int preced(char ch) 55 | { 56 | switch(ch) 57 | { 58 | case '(': 59 | return 0; 60 | case '+': 61 | case '-': 62 | return 1; 63 | case '*': 64 | case '/': 65 | return 2; 66 | case '^': 67 | return 3; } } 68 | 69 | void in_to_post(char infix[]) 70 | { 71 | int length; 72 | static int i=0,pos=0; 73 | char symbol,temp; 74 | char postfix[40]; 75 | length=strlen(infix); 76 | push('('); 77 | while(i=preced(symbol)) 99 | { 100 | temp=pop(); 101 | postfix[pos]=temp; 102 | pos++; 103 | } 104 | push(symbol); 105 | break; 106 | default: 107 | postfix[pos++]=symbol; 108 | break; 109 | } 110 | i++; } 111 | while(top>0) 112 | { 113 | temp=pop(); 114 | postfix[pos++]=temp; } 115 | postfix[pos++]='\0'; 116 | printf("\nAfter Converting Infix To Postfix Expression: "); 117 | puts(postfix); 118 | return; } 119 | --------------------------------------------------------------------------------