- Developed at AT & T’s Bell Laboratories of USA in 1972. Designed and written by Dennis Ritche.
- Output Statement Syntax= printf("control string",variable); //included in stdio.h Header file
ex- printf("Hello");
Escape Sequence Character= \n(new line), \t(tab), \a(alert), \b(backspace)
Format Specifier= %d(integer), %f(float), %c(char)
ex- printf("%d",c); // will print value of c
- Program to print Variable's Value
#include<stdio.h>
void main()
{
int a=50;
float b=7.5;
char c='w';
printf("Value of a is %d",a);
printf("\nValue of a is %f",b); // %.2f = 7.50 two digits after decimal
printf("\nValue of a is %c",c);
}
o/p=
Value of a is 50
Value of a is 7.500000
Value of a is w
[Note- While using Ubantu, don't include conio.h Header File(U Can't use getch(),clrscr(),exit(),etc.)]
To Start Terminal press- Ctrl+Alt+t
To Write/Read Code type- $gedit FileName.c
To Complie and Run type- $gcc FileName.c -o AlternateFileName
$./AlternateFileName
- Input statement syntax= scanf("Format specifier",&variable);
- Program for Addition
#include<stdio.h>
void main()
{
int a,b,c;
printf("Enter 2 integer values ");
scanf("%d %d",&a,&b);
//dont give space between last format specifer and double qoutes (%d")
//dont give space between last format specifer and double qoutes (%d")
// otherwise it will accept one more character from user
c=a+b;
c=a+b;
printf("Addition is %d",c);
}
o/p=
Enter 2 integer values 10 20
Addition is 30
No comments:
Post a Comment