Pages

Wednesday, 31 March 2021

Basic structure of a “C” program:-

Documentation Section

/* Program for addition of 2 numbers */

Link Section (or) 
Preprocessor Directives
#include<stdio.h>
#include<conio.h>

Definition section

#define pf printf

Global Declaration Section

 

Main() Function Section

          

           main()

           {

              Declaration part;

              Execution part;

           }

Main() Function Section

 

    main()

     {

       int a,b,c;

       clrscr();

       printf(“Enter a and b values:”);

       scanf(“%d%d”,&a,&b);

       c=a+b;

       printf(“sum is %d”,c);

    }

Sub Program Section (or)

User-defined function Section

Function 1

Function 2

-----------------

Function n

 


Write a “C” program to print a message.

Method 1:-
/*print a message 
  of your choice */
#include<stdio.h>
#define pf printf
main()
{
pf(“welcome to “C”);
}
Method 2:-
//print a message
#include<stdio.h>
#define pf printf
Void main()
{
pf (“welcome to “C”);
}
Method 3:-
//print a message
#include<stdio.h>
#define pf printf
int main()
{
Pf(“welcome to “C”);
return 0;
}


/* Program to illustrate the different data types and there number of bytes occupied */
#include<stdio.h>
#include<conio.h>
void main()
{
 int a=22;
 char b[]="raj kumar";
 char c='f';
 float d=143.5;
 double e=1234.54;
 clrscr();
 printf("\n the string is : %s",b);
 printf("\n the character is :%c",c);
 printf("\n the number of bytes occupied by char is :%d",sizeof(c));
 printf("\n");
 printf("\n the integer is %d",a);
 printf("\n the number of bytes occupied by int is :%d",sizeof(a));
 printf("\n");
 printf("\n the float value is %f",d);
 printf("\n the number of bytes occupied by flaot is :%d",sizeof(d));
 printf("\n");
 printf("\n the double value is %lf",e);
 printf("\n the number of bytes occupied by double is :%d",sizeof(e));
 getch();
}

output:


//Program to illustrate the Local and Global variables 

#include<stdio.h>
#include<conio.h>
int global;
void main()
{
 int local;
 clrscr();
 printf("\n the local variable is : %d",local);
 printf("\n the global variable is : %d",global);
 getch();
}

output:

No comments:

Post a Comment

Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...