[Home Page] [Back] [Content of Contributions] [Movement: Green Leaf World]
Program 01
#include<stdio.h> //HEADER FILE INCLUSION
int main (void)
{
//VARIABLE DECLARATION AREA
int a;
char b;
float c;
system("clear"); //in windows use clrscr();
printf("\n\n\t\t\tThis is Our First C Program\n\n"); //PRINTING MESSAGE
scanf("%c", &b);
scanf("%d", &a);
scanf("%f", &c);
printf("%c", b);
printf("%d", a);
printf("%f", c);
return(1);
}
int main (void)
{
//VARIABLE DECLARATION AREA
int a;
char b;
float c;
system("clear"); //in windows use clrscr();
printf("\n\n\t\t\tThis is Our First C Program\n\n"); //PRINTING MESSAGE
scanf("%c", &b);
scanf("%d", &a);
scanf("%f", &c);
printf("%c", b);
printf("%d", a);
printf("%f", c);
return(1);
}
Output:
This is Our First C Program
a
10
10.123
a1010.123000skm@skm-ThinkPad-L430:~$
a
10
10.123
a1010.123000skm@skm-ThinkPad-L430:~$
Program 02
#include<stdio.h>
int main (void)
{
int a;
char b;
float c;
system("clear");
printf("\n\n\t\t\tThis is Our Second C Program\n");
printf("\nEnter a character: ");
scanf("%c", &b);
printf("\nEnter an Integer: ");
scanf("%d", &a);
printf("\nEnter a Real Number: ");
scanf("%f", &c);
printf("\n\nEntered character: ");
printf("%c", b);
printf("\nEntered integer: ");
printf("%d", a);
printf("\nEntered real no: ");
printf("%f\n\n", c);
return(1);
}
int main (void)
{
int a;
char b;
float c;
system("clear");
printf("\n\n\t\t\tThis is Our Second C Program\n");
printf("\nEnter a character: ");
scanf("%c", &b);
printf("\nEnter an Integer: ");
scanf("%d", &a);
printf("\nEnter a Real Number: ");
scanf("%f", &c);
printf("\n\nEntered character: ");
printf("%c", b);
printf("\nEntered integer: ");
printf("%d", a);
printf("\nEntered real no: ");
printf("%f\n\n", c);
return(1);
}
Output:
Enter a character: a
Enter an Integer: 10
Enter a Real Number: 10.123
Entered character: a
Entered integer: 10
Entered real no: 10.123000
skm@skm-ThinkPad-L430:~$
Program 03
#include<stdio.h>int main (void)
{
int a;
char b;
float c;
system("clear");
printf("\n\n\t\t\tThis is Our Third C Program\n");
printf("\nEnter a character: ");
scanf("%c", &b);
printf("Enter an Integer: ");
scanf("%d", &a);
printf("Enter a Real Number: ");
scanf("%f", &c);
printf("\n\nEntered character: %c", b);
printf("\nEntered integer: %d\nEntered real no: %f\n\n", a, c);
getchar();
return(8);
}
Output:
This is Our Third C Program
Enter a character: a
Enter an Integer: 10
Enter a Real Number: 10.123
Entered character: a
Entered integer: 10
Entered real no: 10.123000
skm@skm-ThinkPad-L430:~$
Remember:
- printf(), scanf(), system(), getchar() are library functions. We must include stdio.h header file to use any of this functions in a program code.
- A C program code is also called source code.
- Any C program code must be compiled before execute.
- Once a program code is compiled, you may execute it several times.
- It is a good practice to show messages before any input statement.
- You must be aware about visibility & clarity of the outputs.
- "%" with printf()/ scanf() is used as format specifier to define the format of the data. The formats are
- %d - Integer(signed)
- %u - Integer(unsigned)
- %ld - Integer(Long signed)
- %c - Character(char)
- %f - Real(float)
- %lf - Real(Double)
- %Lf - Real(Long Double)
- etc.
No comments:
Post a Comment