0% found this document useful (0 votes)
21 views14 pages

C Program

The document provides instructions on how to write a C program to print a name. It explains how to include header files, use functions like printf and getch, and gives several code examples to output a name, input and display a name, and display additional information like name and age.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views14 pages

C Program

The document provides instructions on how to write a C program to print a name. It explains how to include header files, use functions like printf and getch, and gives several code examples to output a name, input and display a name, and display additional information like name and age.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Write a Program to Display your Name in C

To Write a Program to Display your Name in C we Have Print Function for


that (Actually more Options in C Language to Print our Names but we are
going to Discuss only This Print Function methods in this Tutorial).
Where Print Function take any String or Numeric value from users and Print
that Value in the Output screen when we run our C Program.

my.c
#include<stdio.h>
void main()
{
printf("Name : John");
getch(); //to add a Pause
}

So if you want to know Write a Program to Display your Name in C then you
need to Write Print function inside your C Program and between the Print
functions double Quotes you need to write your Name.

Like : printf(“My Name“);

1) First Open You C Programming Software (Turbo C++)


2) Create New File And Save that New File With myname.c name. (here
myname is out file name and .c is out C program’s Extension that will help
our compiler to understand our program’s programming language.)
3) Write this code As shown Below:
4) Run your program by pressing ctrl+f9 (Turbo c++ user).

Print your Name using C Program


getch( ):

Usually getch() (getch function) is used to read a character from screen. But
here we are using this to add a Pause to our Output Screen. If we don’t add
this in our program, our program’s output screen will close quickly after
running our program.

clrscr( ):
When we run our C Program for 1st time we Get our value. but after making
some changes to our C program when we run the program we get out new
output with the old output.
To remove those Old/Previews Output/Results values, We use clrscr();.
Where clr(Clear) and scr(Screen) stands for Clear Screen (clrscr).

Printing Name Using C Language

my.c
#include<stdio.h>
void main()
{
printf( " My Name Is Human " );
getch();
}

All used Steps (Explained) to Display name in C:


#include<stdio.h> :

#include<stdio.h> is a Header file that includes Slandered (str) Input Output


(IO) Library/File. Because All Of the C’s In build Functions are declared in
<stdio.h> File

Main Function main( ) :


main() main function is the entry point of C program. When We Run our C
program the execution Control Directly to the main() (main function) and
gave us result in output.

Print Function printf( ) :

printf() is also a Function of C. Print function is used to print “character,


string, float, integer,etc” to the output screen.
So what ever we write between printf() inverted commas (” “) that will be
printed on the output Screen.

Write a Program to Display your Name in C


C Program to input name and Display

For your Question “C Program to input name and Display“, We have to get
user input first then we have to Store and Display user Input at the END.
For this we are going to use scanf() function.
and a variable where we will store input data like Name.
Below we have a C Program where we will get Name from user input and
after that we will display entered name at the End

my.c
#include<stdio.h>
void main()
{
char name[20];
printf("Enter Your Name : ");
scanf("%s",&name);
printf("Your name is : %s", name);
getch();
}
Write a program to Print your name in c

Here is a C Program that can display your given name when you run this C
Program.
We have used printf() function to Print your Name.

my.c
#include<stdio.h>
void main()
{
printf("My Name is John");
getch();
}
You also can use clrscr() Clear Screen C Function before print() Function to
clear old outputs.

C program to print name and address

To print your Name or Address we can use Same C Print Function (printf())
for both.
Just write your name inside The C Function
[ printf(“Name and Address“); ].

my.c
#include<stdio.h>
void main()
{
printf("My Name is John and My Address is : 21 Jump Street NewYork");
getch(); //add a Pause
}
Write a program to print your name at the center of the screen

To print or write a program to print your name at the center of the screen.
We have to use C Language’s gotoxy() function.
Where we need to provide X and Y digits to Perfectly align our Name at the
Center of the Screen.

my.c
#include<stdio.h>
void main()
{
gotoxy(40,13);
printf("Rosie");
getch();
}
write a c program to display your name

Again in this Question “write a c program to display your name” we are


going to write a C program, Where by using Printf Function we will print our
Name to the Output Screen.

my.c
#include<stdio.h>
void main()
{
clrscr();
printf("My Name is John");
getch();
}

name of the program printed

I am not able to Understand this Question. So i will assume that You want a
Program to Print Names.
So if this is your Question, Then above we have so many Programs to do that.
But if you want to know what name or how we can Name our program that
will print our name, Then its so simple.
Just flick “File” Option from the Menu
From there Select “Save” Option
(if nothing is happening the select “Save As” Instead of “Save”)
Give a Name for your file Followed by .c Extortion.
for Example : myfile.c
Now select Done or Save.

how to print name in c

To print name is c, we have to use printf() function.


Where we have to write our name inside this function.
This will Print our name at the Output screen on execution.

my.c
#include<stdio.h>
void main()
{
clrscr();
printf("My Name is John");
getch();
}

name in c language

Name in c language is treated as String. Where we have Char Data type to


store Character/String values.
But You name to include more than one Character that’s why we have to
store all the character in an array.
So using char name[arraylength] we store our name in C variables.
but if you just want to print your name (without storing it inside a Variable)
Then we can use printf() function.

my.c
#include <stdio.h>
int main()
{
char name[20] = "John";
printf("My name is %s", name);
printf("\nMy name is John without Variable");
getch();
}
& name in c

We we are storing names using C Scanf function then we use this “&” sign or
&name in c.
Where &name will store input data to given variable (which is name).

my.c
#include <stdio.h>
int main()
{
char name[20];
printf("Enter your Name\n");
scanf("%s",&name);
printf("\nYour name is = %s",name);
getch();
}
c program to print name using array

When we store our name inside the C Character datatype. Then to store all
the character we give array length after the variable name (name[10]).
So we can say that we are storing our name using arrays.
But if you want to store your name in the array manually then you can also
do that.
But the problem is, we have to run C Loop to print every single Character
from our name.

my.c
#include<stdio.h>
void main()
{
char name[] = {'j','o','h','n'};
int i=0;
while(i<sizeof(name)){
printf("%c",name[i]);
i++;
}
getch();
}
How to input a name in c

To get user inputs like input a name in c we have scanf function.


Where we have to give a Data type address specifier with variable name with
& sign.

But there are 2 methods.


Just using Printf function
get name and age first then print it
So in 1st method we will just use printf function
and in 2nd method, we will

my.c
#include <stdio.h>
int main()
{
char name[20];
printf("Enter your Name\n");
scanf("%s",&name);
printf("\nYour name is = %s",name);
getch();
}
write a program to enter your name and print it

To enter your name and print it. we have to declare a variable,


store input values to our variables
then print the stored values using printf function.
char name[10];
int age;
will declare variables for name and Age
Where Scanf function will store all the values
and printf will print all the stored values at the End.

my.c
#include <stdio.h>
int main()
{
char name[20];
printf("Enter your Name\n");
scanf("%s",&name);
printf("\nYour name is = %s",name);
getch();
}

c program to display name and age

To print Name and Age we have to deal with Characters and Integer values.
Where for storing Character Values we have CHAR data type
and for integers with have INT data type.
And for address/format specifier we have %s for String and %d for
Integers/Digits.
Here here is the C Program display name and Age.

my.c
#include<stdio.h>
int main()
{
char name[20];
int age;
printf("Enter your Name\n");
scanf("%s",&name);
printf("\nEnter your Age\n");
scanf("%d",&age);
printf("\nYour name is = %s",name);
printf("\nYou are %d Years OLD",age);
getch();
}

But if you don’t want to get and store the Age and Name then you can insert
or give the AGE and NAME manually.

my.c
#include <stdio.h>
int main()
{
char name[20] = "John";
int age = 25;
printf("\nYour name is = %s",name);
printf("\nYou are %d Years OLD",age);
getch();
}

and if you don’t even want to use Variables the write all the Info about name
and age inside C Printf function.

my.c
#include<stdio.h>
int main()
{
printf("\nMy name is = John");
printf("\nI am 25 Years OLD");
getch();
}

You might also like