C programs to create and print a string

PROGRAM1:

#include <stdio.h>
void main()
{
    char str[10]={'p','r','o','g','r','a','m'};
    printf("%s",str);
}


OUTPUT:

program

PROGRAM2:

#include <stdio.h>
void main()
{
    char str[10]="program";
    printf("%s",str);


OUTPUT:

program

PROGRAM3:

#include <stdio.h>
void main()
{
    char str[20];
    printf("Enter a string\n");
    scanf("%s",str);
    printf("Entered string is %s\n",str);
}


OUTPUT:

Enter a string
hello
Entered string is hello


PROGRAM4:

#include <stdio.h>
#include<string.h>
void main()
{
    char str[20];
    printf("Enter a string\n");
    gets(str);
    puts(str);
}

OUTPUT:

Enter a string
hello
hello

Popular Posts