Read and print string

Q. Write a simple C program to accept your name and print it.

Ans.

/*c program to introduction of string*/
/*c program to accept your name and print it*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 printf("Enter your name : ");
 gets(str);
 puts(str);
 getch();
 return 0;
}

/***************Output*******************/
Screen shot for read and print string via gets() and puts()



/*Another way to write above program to intro of string*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char str[30];
 printf("Enter your name : ");
 scanf("%s", &str);
 printf("Your name is %s",str);
 getch();
 return 0;
}


/***************Output*******************/
Screen shot for read and print string via scanf() and printf()


Related Programs:

Comments