Program to Print Sentence in C

 

Print Sentence in C Language:

 On this page we will discuss about how to print sentence in C language.A fundamental  data structure that is used in many different fields is the string. In many programs or cases we required data from user or we need to print the data to make the result visible to user.Hence input and output of string is an important topic.

print sentence in C language

How to print sentence in C language?

To print a sentence in C language we use printf() function.printf( ) is a function which is already builtin at <stdio.h> library.Its’s role is to display sentence,numbers, etc as output.

Syntax:

printf("your text");

whatever we want to print  we have to write that text in place of your text in the above syntax.semicolon(;) is use at the end of every function it indicated the compiler that the function terminates here.

Program 1:

 

Run
#include <stdio.h>
int main() 
{
   // printf() displays the string inside quotation
    printf("PrepInsta is the  most visited website for Placements in India.");
   return 0;
}

Output:

PrepInsta.com most visited website for Placements in India.
  • In the first line of code stdio.h is the standard input output library which includes printf(),scanf() and other basic built-in functions.
  • So to include standard input output library or stdio.h in our program we use preprocessor know as #include.
  • #include tells the compiler to include stdio.h
  • printf( )  is used to print the string and number in C language.
  • scanf( ) is used to take input from user
  •  If we use printf( )  or scanf ( ) without #include<stdio.h> the compiler will give error and the program will not compile.
  • From main( )  function execution of program begins.
  • In this program the printf( )  will display ” PrepInsta.com most visited website for Placements in India.”
  • Return 0 indicated the ending of program which measn return statement tells the exit status.

 

Program 2: To Print Sentence in C

 

Run
#include <stdio.h>
int main ()
{
  char arr[20];
  printf ("Enter your  name: ");
  scanf ("%s", arr);
  printf ("Welcome to PrepInsta , %s", arr);
  return 0;
}

Output:

Enter your  name: Rohan
Welcome to PrepInsta , Rohan

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription