Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

๐Ÿ”ท Square Star Pattern ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Column-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Row-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; ...

WAP to replace each string of one or more blanks by a single blank in c

Description:

  • Input string:
    • Pointers         are      sharp           knives.
  • Output String:
    • Pointers are sharp knives.
  • Blank can be spaces or tabs. (replace with single space).
Pr-requisites:-
  • Functions
  • Pointers

Objective: -

  • To understand the concept of
    • Functions, Arrays, and Pointers

Inputs: -

  • String with multi-spaces between words
Sample execution: -
Test Case 1:

Enter the string with more spaces in between two words
Pointers     are               sharp     knives.

Pointers are sharp knives. 

Test Case 2:


Enter the string with more spaces in between two words

Welcome                to india

Welcome to india


PROGRAM : 

-----------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include<string.h>

void space(char str[])
{
    int i,k=0;
    while(str[k]!='\0')
    {
        if((str[k]==' ' && str[k+1]==' ') || (str[k]=='\t' && str[k+1]=='\t'))
        {
            i=k;
            while(str[i]!='\0')
            {
                str[i]=str[i+1];
                i++;
            }
             k--;
        }
        k++;
    }
}

int main()
{
    char str[200];
    
   // printf("Enter the string with more spaces in between two words\n");
    scanf("%[^\n]", str);
    
   space(str);
    
    printf("%s\n", str);
}
-----------------------------------------------------------------------------------------------------------------------------


Comments

Popular Posts

๐ŸŒ™