1.#include <stdio.h>
double f1(double x)
{ return x*x; }
double f2(double x, double y)
{ return x*y; }
double fun(double a, double b)
{
/**********found**********/
double(*f)();
double r1, r2;
/**********found**********/
f =fl ;
r1 = f(a);
/**********found**********/
f = f2 ;
r2 = (*f)(a, b);
return r1 + r2;
}
void main()
{ double x1=5, x2=3, r;
r = fun(x1, x2);
printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n",x1, x2, r);
}
2.#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct aa
{ int data;
struct aa *next;
} NODE;
int fun (NODE *h)
{ int sum=0;
NODE *p;
p=h->next;
/*************found**************/
while(p!=next)
{ if(p->data%2==0)
sum+=p->data;
/*************found**************/
p=p->next;
}
return sum;
}
NODE *creatlink(int n)
{
NODE *h,*p,*s;
int i;
h=p=(NODE*)malloc(sizeof(NODE));
for(i=1;i<n;i++)
{
s=(NODE*)malloc(sizeof(NODE));
s->data=rand()%16;
s->next=p->next;
p->next=s;
p=p->next;
}
p->next=NULL;
return h;
}
void outlink(NODE *h)
{ NODE *p;
p=h->next;
printf("\n\n The LIST :\n\n HEAD");
while(p)
{ printf("->%d",p->data);
p=p->next;}
printf("\n");
}
void main()
{ NODE *head; int sum;
system("CLS");
head=creatlink(10);
outlink(head);
sum=fun(head);
printf("\nSUM=%d",sum);
}
3.
#include <stdio.h>
#define N 80
int fun(char *str)
{
}
void main()
{
char s[N];
FILE *out;
char *test[]={"1234321","123421","123321","abcdCBA"};
int i;
printf("Enter a string : ");
gets(s);
printf("\n\n");
puts(s);
if(fun(s))
printf("YES\n");
else
printf("NO\n");
/************************************/
out=fopen("out.dat","w");
for(i=0;i<4;i++)
if(fun(test[i]))
fprintf(out,"YES\n");
else
fprintf(out,"NO\n");
fclose(out);
/************************************/
}