Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

03 C Programming

C Programming lec -3 notes

Uploaded by

pnkulkarni05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

03 C Programming

C Programming lec -3 notes

Uploaded by

pnkulkarni05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

C PROGRAMMING

INDEX
1 Printf and Scanf in c

2 Comments in C
 The printf() and scanf() functions are used for input
and output in C language.

 Both functions are inbuilt library functions.

 Both function defined in stdio.h (header file).


printf() function

 The printf() function is used for output.

 It prints the given statement to the console.

 The syntax of printf() function is given below

printf("format string",argument_list);

The format string can be %d (integer),


%c (character),
%s (string),
%f (float) etc.
Integer

#include<stdio.h>
#include<conio.h>

void main(){

int a = 10;

printf("%d",a);

}
Float

#include<stdio.h>
#include<conio.h>

void main(){

float b = 10.20;

printf("%f",b);

getch();

}
Char

#include<stdio.h>
#include<conio.h>

void main(){

char c = 'c';

printf("%c",c);

getch();

}
Double

#include<stdio.h>
#include<conio.h>

void main(){

double d = 465.568;

printf("%.3lf",d);

getch();

}
scanf() function

 The scanf() function is used for input

 It reads the input data from the console.

scanf("format string",argument_list);
Get Value from user

#include<stdio.h>
#include<conio.h>

void main()
{

int a;

printf("Enter value for a : ");


scanf("%d",&a);

printf("Value you entered is %d",a);

getch();

}
 Program to print sum of given number :

#include<stdio.h>
#include<conio.h>

void main(){

int a;
int b;
int sum;

printf("Enter first number : ");


scanf("%d",&a);

printf("Enter second number : ");


scanf("%d",&b);

sum = a+b;

printf("Total is : %d",sum);

}
 OUTPUT :
COMMENTS IN C
 Comments in C language are used to provide
information about lines of code.

 It is widely used for documenting code.

 Comments are ignored by the compiler.


 There are 2 types of comments in C language.

➢ Single Line Comments

➢ Multi Line Comments


Single Line Comments

 Single line comments are represented by double slash


//.

printf("Hello C"); //printing information


MultiLine Comments

 Multi line comments are represented by slash


asterisk /* ... */.

void main(){

/*printing
information*/

printf("Hello C");

 }
*****************************************************

You might also like