Posts

PYRAMID STAR PATTERN

Image
Consider the following I/O samples. SAMPLE INPUT:   3 SAMPLE OUTPUT:                                                 *                                                        * *                                                  * * *              C PROGRAM:    #include <stdio.h> int main() {     int row,col,spc,n;     scanf("%d",&n);     for(row=1; row<=n; ++row)     {         for(spc=1; spc<=n-row; spc+...

SQUARE STAR PATTERN

Image
Consider the following I/O samples. SAMPLE INPUT:   3 SAMPLE OUTPUT:                                                                                         * * *                                                                            * * *                                                               ...

MIRRORED RIGHT TRIANGLE STAR PATTERN

Image
Consider the following I/O samples. SAMPLE INPUT:   5 SAMPLE OUTPUT:                    C PROGRAM:    #include <stdio.h> int main() {     int row,col,n;     scanf("%d",&n);     for(row=1; row<=n; ++row)     {         // Print spaces         for(col=row; col<n; ++col)         {             printf("  ");         }          // Print star         for(col=1; col<=row; ++col)         {             printf("* ");         }        printf("\n");     }     return 0; } OUTPUT:   The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++  an...

RIGHT TRIANGLE STAR PATTERN

Image
Consider the following I/O samples. SAMPLE INPUT:   5 SAMPLE OUTPUT:                                                   *                                           * *                                             * * *                                             * * * *                                             * * * * * ...

NUMBER OF ODD AND EVEN NUMBERS IN AN ARRAY

Image
Consider the following I/O samples. SAMPLE INPUT:  1 2 3 4 5 6 7 8 9 10 SAMPLE OUTPUT:  ODD = 5                                                                                   EVEN = 5 C PROGRAM:    #include<stdio.h> int main() {    int arr[100];    int i, n,even=0,odd=0;    printf("Enter the number of elements:");    scanf("%d",&n);    printf("Enter the array elements:");    for(i=0;i<n;i++)    scanf("%d",&arr[i]);    for(i=0;i<n;i++)    {         if(arr[i]%2==0)             even++;         else             odd++;   ...

C PROGRAM FOR BALANCED EXPRESSION

Image
Consider the following I/O samples. SAMPLE INPUT 1:  [10+(6-2)/{3-1}]          SAMPLE OUTPUT 1 :   VALID         SAMPLE INPUT 2:  (([a-z]+{c-d}/a)-d)/n) SAMPLE OUTPUT 1 :   INVALID   C PROGRAM: #include <stdio.h> #include <stdbool.h> #include <string.h> #define MAX_SIZE 100 int top=-1; char arr[MAX_SIZE]; int isEmpty() {     if(top == -1)         return true;     else         return false; } int isFull() {     if(top == MAX_SIZE-1)         return true;     else         return false; } void push(char item) {     if(isFull())         printf("Stack is full");     else         top++;         arr[top] = item; } void pop() {     if(isEmpty())         printf("Stack is emp...

C PROGRAM TO CHECK BALANCED PARENTHESIS - ( { [

Image
Consider the following I/O samples. SAMPLE INPUT 1:  [ { ( )  } ]             SAMPLE OUTPUT 1 :   VALID         SAMPLE INPUT 2:  [ { ] } SAMPLE OUTPUT 1 :   INVALID   C PROGRAM: #include<stdio.h> #include<string.h> #define N 100 char stack[N]; int i=-1; //push parenthesis into stack void push(char data)                 {     i++;     if(i>=N)         printf("Stack is full");     else         stack[i]=data; } //pop parenthesis out from the stack void pop() {     if(i == -1)         printf("Cannot remove");     else         i--; } char top() {     return stack[i]; } int empty() {     if(i == -1)         return 1;  // stack empty     else     ...