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:
programPROGRAM2:
#include <stdio.h>void main()
{
char str[10]="program";
printf("%s",str);
}
OUTPUT:
programPROGRAM3:
#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 stringhello
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 stringhello
hello