Social Icons

banner image

Mini header files in c and how to work with a macro in c

Mini Header Files in C And How To Work With A Macro In c

ERROR COPY:-

 #include <stdio.h>  
 #include<conio.h>
  
 #define    CCPLUSPLUS  "ccplusplus"  
   
 int main () {  
    #ifndef CCPLUSPLUS 
    printf("N is not defined"); 
   
        #error c is required, so what can i do???  
    #endif  
      getch();
   // return 0;  
 }  

HEADER 1 COPY:-

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

//#include"head1.h"

int main()
{
    int a=10,b=20;
    sum(a,b);
    diff(a,b);
    getch();
}

IFDEF.C:-

#include<stdio.h>
#include<conio.h>
#define N 10
 
 int main()
 {
     #ifndef N
     
     printf("N is not defined");
     
     #else
     
     printf("N defined");
     
     #endif
     
     getch();
     }

MAC PROGRAME:-

#include<stdio.h>
#include<conio.h>
#define MAX(x, y) ((x)>(y)) ? (x):(y)

int main()
{
int i=10, j=5, k=0;
    k = MAX(i, j++);
printf("%d, %d, %d\n", i, j, k);
getch();
}


MACRO PROGRAME:-

#include<stdio.h>
#include<conio.h>
#define area(r) r*3.14
int main()
{
        float a;
        a=area(6);
        printf("Area circle=%f",a);
        getch();
}

MAIN PROGRAMME:-

#include <stdio.h>
#include "util.h"

#define MAX 10

int a[MAX];

int main()
{
    int i,t,x,y;
    /* fill array */
    for (i=0; i < MAX; i++)
    {
        a[i]=rand();
        printf("%d\n",a[i]);
    }

    bubble_sort(MAX,a);

    /* print sorted array */
    printf("--------------------\n");
    for (i=0; i < MAX; i++)
        printf("%d\n",a[i]);
}

SQUARE.C:-

#include"C:\Users\Gurman\Desktop\sq.h"
double square(double x)
{
   return x * x;
}

TEST.C:-

#include <stdio.h>
#include "C:\Users\Gurman\Desktop\sq.h"

int main()
{

int i;
scanf("%d", &i);
printf("%g\n", square(i));
}

UTIL.C:-

/* util.c */
#include "util.h"

int rand_seed=10;

/* from K&R
 - produces a random number between 0 and 32767.*/
int rand()
{
    rand_seed = rand_seed * 1103515245 +12345;
    return (unsigned int)(rand_seed / 65536) % 32768;
}

void bubble_sort(int m,int a[])
{
    int x,y,t;
     for (x=0; x < m-1; x++)
        for (y=0; y < m-x-1; y++)
            if (a[y] > a[y+1])
            {
                t=a[y];
                a[y]=a[y+1];
                a[y+1]=t;
            }
}

AREA MACRO:-

#include<stdio.h>
#include<conio.h>
#define Pi 3.14
int main()
{
    float area,r;
    printf("enter the value of r");
    scanf("%f",&r);
    area=Pi*r*r;
    printf("area=%f",area);
    getch();
}
Mini header files in c and how to work with a macro in c Mini header files in c and how to work with a macro in c Reviewed by Marketing Thrills on September 04, 2015 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.