Friday, May 30, 2014

PROGRAM ON ENUM

#include<stdio.h>
#include<conio.h>
void main()
{
enum mon
{
jan=1,feb,mar,apr=1,may,jun
}m1,m2;
enum month
{
apr,
jul=1   //invalid- multiple declaration for apr
}m3;
clrscr();
printf("m1=%d",m1);      // m1=garbage value
m1=jan;             //assign m1 an enumerator
printf("\nm1=%d",m1);    //m1=1
m1=1;               //assign m1 an integer constant since m1 can hold integer value
printf("\nm1=%d",m1);    //m1=1
m1=8;
printf("\nm1=%d",m1);  //m1=8
printf("\n enter the value of m\n");
scanf("%d",&m1);
printf("\nm1=%d",m1);  //m1=value given by user
//feb=5; lvalue required
//u can directly print value of an enumerator
printf("\n%d",may); //2
m2=aug; //invalid
getch();
}

FILE HANDLING- USE OF FPRINTF & FSCANF

#include<conio.h>
#include<stdio.h>
void main()
{
  FILE *fp1;
  typedef struct student
  {
  char name[20];
  int age;
  }stu;
  stu s1;
  int i,n;
  clrscr();
  fp1=fopen("stu.txt","w");
  if(fp1==NULL)
  {
printf("file creation error\n");
getch();
exit(1);
  }
  printf("enter the no of students\n");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
printf("enter the name and age\n");
scanf("%s%d",s1.name,&s1.age);
fprintf(fp1,"%s %d\n",s1.name,s1.age);
  }
  fclose(fp1);

  fp1=fopen("stu.txt","r");
  if(fp1==NULL)
  {
printf("file does not exist\n");
getch();
exit(1);
  }
  else
  {
  while((fscanf(fp1,"%s%d",s1.name,&s1.age))!=EOF)
{
printf("name=%s age=%d\n",s1.name,s1.age);
}
  }
  fclose(fp1);
  getch();
}

FILE HANDLING USE OF FGETS & FPUTS

#include<conio.h>
#include<stdio.h>
void main()
{
  char str[30];
  FILE *fp1;
  clrscr();
  fp1=fopen("test2.txt","w");
  if(fp1==NULL)
  {
printf("file creation error\n");
getch();
exit();
  }
  else
  {
printf("enter the text\n");
while(gets(str)!=NULL)
{
  fputs(str,fp1);
  fputs("\n",fp1);
}
  }
  fclose(fp1);

  fp1=fopen("test2.txt","r");
  if(fp1==NULL)
     {
printf("file does not exist\n");
getch();
exit();
     }
  else
     {
while(fgets(str,30,fp1)!=NULL)
{
  puts(str);
}
     }
  fclose(fp1);
  getch();
}

FILE HANDLING USE OF FPUTW & FGETW

 #include<conio.h>
 #include<stdio.h>
 void main()
 {
  FILE *fp1;
  int i,n,val;
  clrscr();
  fp1=fopen("num1.dat","wb");
  if(fp1==NULL)
  {
     printf("file creation error\n");
     exit();
  }
 else
 {
     printf("enter the no of values\n");
     scanf("%d",&n);
     printf("enter the values\n");
     for(i=1;i<=n;i++)
     {
scanf("%d",&val);
putw(val,fp1);
     }
 }
 fclose(fp1);

 fp1=fopen("num1.dat","rb");
 if(fp1==NULL)
   {
printf("file does not exist\n");
getch();
exit();
   }
 else
   {
val=getw(fp1);
while(!feof(fp1))  //this will check for real end of file
//while(val!=EOF)  //this will stop reading as it get val=-1 even before real EOF
{
   printf("\n%d",val);
   val=getw(fp1);
}
   }
 fclose(fp1);
 getch();
 }

FILE HANDLING USE OF FPUTC & FGETC

#include<stdio.h>
#include<conio.h>
void main()
{
  FILE *fp1;
  int ch;
  clrscr();
  fp1=fopen("test1.txt","w");
  if(fp1==NULL)
  {
     printf("file creation error\n");
     getch();
     exit();
  }
  else
  {
     printf("enter the character\n");
     ch=getchar();
     while(ch!=EOF)
     {
     fputc(ch,fp1);
     ch=getchar();
     }
  }
  fclose(fp1);

  fp1=fopen("test1.txt","r");

  if(fp1==NULL)
  {
     printf("file does not exist\n");
     getch();
     exit();
  }
  else
  {
     ch=fgetc(fp1);
     while(ch!=EOF)
     {
printf("%c",ch);
ch=fgetc(fp1);
     }
  }
  fclose(fp1);
  getch();
}

WRITE A PROGRAMME TO COMPARE THE MEMORY ALLOCATIONS BETWEEN STRUCTURE AND UNION VARIABLE

#include<stdio.h>
#include<conio.h>
void main()
{
typedef union
{
int roll;
char grade;
float per;
}uni1;

typedef struct
{
int roll;
char grade;
float per;
}str1;

uni1 u1;
str1 s1;
clrscr();
printf("\nSTRUCTURE");
printf("\nsize of s1 is %d",sizeof(s1));
printf("\naddress of s1 is %u",&s1);
printf("\naddress of s1.roll is %u",&s1.roll);
printf("\naddress of s1.grade is %u",&s1.grade);
printf("\naddress of s1.per is %u",&s1.per);

printf("\nUNION");
printf("\nsize of u1 is %d",sizeof(u1));
printf("\naddress of u1 is %u",&u1);
printf("\naddress of u1.roll is %u",&u1.roll);
printf("\naddress of u1.grade is %u",&u1.grade);
printf("\naddress of u1.per is %u",&u1.per);
getch();
}

WRITE A PROGRAMME TO READ AND PRINT THE FOLLOWING INFORMATION USING UNION (NAME, ROLLNO, PERCENTAGE, GRADE)

#include<conio.h>
#include<stdio.h>
void main()
{
union student
{
char name[20];
int roll;
float per;
char grade;
}u1;
clrscr();

printf("enter the name\n");
scanf("%s",u1.name);
printf("name->%s\n",u1.name);
printf("enter the roll\n");
scanf("%d",&u1.roll);
printf("roll no->%d\n",u1.roll);
printf("enter the percentage\n");
scanf("%f",&u1.per);
printf("percentage->%f\n",u1.per);
printf("enter the grade\n");
fflush(stdin);
scanf("%c",&u1.grade);
printf("grade->%c",u1.grade);

printf("\nname->%s\n",u1.name);
printf("\nroll no->%d\n",u1.roll);
printf("\npercentage->%f\n",u1.per);
printf("\ngrade->%c",u1.grade);
getch();
}

WRITE A PROGRAM TO READ AND PRINT THE VALUES OF A STRUCTURE VARIABLE USING STRUCTURE POINTER

#include<stdio.h>
#include<conio.h>
void main()
{
typedef struct student
{
int rollno;
char name[20];
}stud;
stud s1,*p1;
p1=&s1;
printf("enter the roll no and name\n");
scanf("%d%s",&(p1->rollno),p1->name);
printf("rollno->%d name->%s",p1->rollno,p1->name);
getch();
}

A PROGRAMME TO ILLUSTRATE THE CONCEPT OF STRUCTURE POINTER AND POINTER IN STRUCTURE

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
typedef struct info
{
int *sno;
char name[20];
}info;
info s1,*p1;
int i=11;
clrscr();
p1=&s1;
s1.sno=&i;
strcpy(s1.name,"AMITA");
printf("%u",&i);
printf("\nsno->%u name->%s ",(p1->sno),p1->name);
printf("\nsno->%d name->%s ",*(p1->sno),p1->name);
getch();
}

WRITE A PROGRAMME TO STORE THE DETAILS OF AN EMPLOYEE WHERE DETAILS CONSIST OF EMPLOYEE'S SNO,NAME,DOB AND DOJ

#include<stdio.h>
#include<conio.h>
typedef struct date
{
int day;
int mon;
int year;
}date;
typedef struct emp
{
int sno;
char name[20];
date dob,doj;
}emp;
void main()
{
int i,n;
emp e1[10];
clrscr();
printf("enter the no employees\n");
scanf("%d",&n);
printf("enter the details of employee\n");
for(i=0;i<n;i++)
{
printf("enter the sno and name of employee\n");
scanf("%d%s%",&e1[i].sno,e1[i].name);
printf("enter the dob of employee\n");
scanf("%d%d%d",&e1[i].dob.day,&e1[i].dob.mon,&e1[i].dob.year);
printf("enter the doj of employee\n");
scanf("%d%d%d",&e1[i].doj.day,&e1[i].doj.mon,&e1[i].doj.year);
}
printf("the details of employee are \n");
for(i=0;i<n;i++)
{
printf("\n");
printf("sno->%d\nname->%s\n",e1[i].sno,e1[i].name);
printf("dob->%d%d%d\n",e1[i].dob.day,e1[i].dob.mon,e1[i].dob.year);
printf("doj->%d%d%d\n",e1[i].doj.day,e1[i].doj.mon,e1[i].doj.year);
}
getch();
}

WRITE A FUNCTION TO CALCULATE THE AVERAGE OF MARKS OF STUDENT AND THEN PRINT THE RESULT IN CALLING FUNCTION

#include<stdio.h>
#include<conio.h>
typedef struct student
{
char name[20];
int rollno;
int age;
int marks[4];
}stu;
float fun1(int*);
void main()
{
stu s1;
int i;
float avg;
clrscr();
printf("enter the name, rollno and age of student\n");
scanf("%s%d%d",s1.name,&s1.rollno,&s1.age);
printf("enter the marks in 4 subjects\n");
for(i=0;i<4;i++)
{
scanf("%d",&s1.marks[i]);
}
avg=fun1(s1.marks);
printf("the average of %s is= %f",s1.name,avg);
getch();
}

float fun1(int *p)
{
int i,sum=0;
float avg;
for(i=0;i<4;i++)
{
sum=sum+*p;
p++;
}
avg=sum/4.0;
return(avg);
}

WRITE A FUNCTION TO READ THE DETAILS OF A STUDENT AND THEN DISPLAY DETAILS IN CALLING FUNCTION

#include<stdio.h>
#include<conio.h>
typedef struct student
{
char name[20];
int rollno;
int age;
int marks[4];
}stu;
stu fun1(stu);
void main()
{
stu s1,s2;
int i;
clrscr();
s2=fun1(s1);
printf("the details of student is:\n");
printf("name-%s\nrollno-%d\nage-%d",s2.name,s2.rollno,s2.age);
for(i=0;i<4;i++)
{
printf("\nmarks in %d subject is- %d",i+1,s2.marks[i]);
}
getch();
}

stu fun1(stu s1)
{
int i;
printf("enter the name, rollno and age of student\n");
scanf("%s%d%d",s1.name,&s1.rollno,&s1.age);
printf("enter the marks in 4 subjects\n");
for(i=0;i<4;i++)
{
scanf("%d",&s1.marks[i]);
}
return(s1);
}

WRITE A PROGRAMME TO STORE INFORMATION OF N STUDENTS WHERE INFORMATION COMPRISES OF STUDENT'S NAME,SNO AND MARKS IN 4 SUBJECTS

#include<stdio.h>
#include<conio.h>
void main()
{
typedef struct student
{
int sno;
char name[20];
int submarks[4];
}stu;
stu s1[10];
int i,n,j;
clrscr();
printf("enter the no of students\n");
scanf("%d",&n);
printf("enter the details of students\n");
for(i=0;i<n;i++)
{
printf("enter sno and name\n");
scanf("%d%s",&s1[i].sno,s1[i].name);
printf("enter the marks in 4 subjects\n");
for(j=0;j<4;j++)
{
scanf("%d",&s1[i].submarks[j]);
}
}
printf("the details of students are\n");
for(i=0;i<n;i++)
{
printf("sno-%d name-%s\n",s1[i].sno,s1[i].name);
printf("the marks in 4 subjects\n");
for(j=0;j<4;j++)
{
printf("marks in %d subject is %d\n",j,s1[i].submarks[j]);
}
}
getch();
}

WRITE A PROGRAMME TO ILLUSTRATE THE DIFFERENT WAYS OF DECLARATION AND INITIALIZATION OF STRUCTURE VARIABLE BY STORING INFORMATION OF THREE STUDENT

#include<conio.h>
#include<stdio.h>
#include<strin.h>
void main()
{
//Different ways of declaring structure variable
struct info
{
int sno;
char name[20];
char add[20];
}s1,s2;

/*struct
{
int sno;
char name[20];
char add[20];
}s3,s4;*/

//struct info s5,s6;

//Different ways of initialising structure varibles
struct info stu1={1,"ajay","dehradun"};

struct info stu2,stu3;
clrscr();
stu2.sno=2;
//stu2.name="rashmi";//wrong
strcpy(stu2.name,"rashmi");
//printf("\n%u",stu2.name);
//printf("\n%u",stu2.sno);
strcpy(stu2.add,"delhi");

printf("enter the sno,name and add of third student\n");
scanf("%d%s%s",&stu3.sno,stu3.name,stu3.add);

printf("\ndetails of students are\n");
printf("\ndetails of 1st stu-> %d\t%s\t%s",stu1.sno,stu1.name,stu1.add);
printf("\ndetails of 2nd stu-> %d\t%s\t%s",stu2.sno,stu2.name,stu2.add);
printf("\ndetails of 3rd stu-> %d\t%s\t%s",stu3.sno,stu3.name,stu3.add);



getch();
}

WRITE A PROGRAMME TO FIND WHETHER A STRING IS PALINDROME OR NOT

#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char s1[20];
int i=0,l,j,flag;
clrscr();
printf("enter the string\n");
scanf("%s",s1);
l=strlen(s1);
for(i=0,j=l-1;i<j;i++,j--)
{
if(s1[i]==s1[j])
{
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1)
printf("\n%s is pallindrome",s1);
else
printf("\n%s is not a pallindrome",s1);
getch();
}

WRITE A PROGRAMME TO IMPLEMENT THE LIBRARY FUNCTIONS-STRLEN,STRCMP,STRLWR,STRUPR,STRREV,STRCPY,STRCAT USING POINTER

//WRITE A PROGRAMME TO IMPLEMENT THE FOLLOWING LIBRARY FUNCTIONS-
//STRLEN,STRCMP,STRLWR,STRUPR,STRREV,STRCPY,STRCAT
//String & Pointer

#include<stdio.h>
#include<conio.h>
int length(char*);
int comp(char*,char*);
void lower(char*);
void upper(char*);
void reverse(char*);
void copy(char*,char*);
void concat(char*,char*);

void main()
{
char s1[20],s2[20],s3[20],s4[20];
int l,i;
clrscr();
printf("enter the first string\n");
gets(s1);
printf("enter the second string\n");
gets(s2);


printf("the length of %s string is- ",s1);
l=length(s1);
printf("%d\n",l);


printf("the result of compairing first and second string-\n");
i=comp(s1,s2);
if(i==0)
{
printf("\n%s and %s are equal\n",s1,s2);
}
else
{
printf("\n %s and %s are not equal with a difference of %d in their ascii value\n",s1,s2,i);
}


printf("\nthe %s string after changing case to lower- ",s1);
lower(s1);
printf("%s\n",s1);


printf("\nthe %s string after changing case to upper- ",s1);
upper(s1);
printf("%s\n",s1);

printf("\n the %s string after being reversed- ",s1);
reverse(s1);
printf("%s\n",s1);


printf("\n %s after being copied by %s is- ",s1,s2);
copy(s1,s2);
printf("%s\n",s1);


printf("enter two strings for applying concatination operation\n");
printf("enter the first string\n");
gets(s3);
printf("enter the second string\n");
gets(s4);
printf("\n%s after being concatenated with %s- ",s3,s4);
concat(s3,s4);
printf("%s\n",s3);


getch();
}

int length(char *p)
{
int i=0;
while(*p)
{
i++;
p++;
}
return(i);
}

int comp(char *p,char *q)
{
int i=0;
while(p[i] && q[i] && (p[i]==q[i]))
{
i++;
}
if(p[i]==q[i])
return 0;
else if(p[i]>q[i])
return(p[i]-q[i]);
else
return(q[i]-p[i]);
}

void lower(char *p)
{
int i=0;
while(p[i])
{
if(p[i]>=65 && p[i]<=91)
 {
   p[i]=p[i]+32;
 }
 i++;
}
}

void upper(char *p)
{
int i=0;
while(p[i])
{
if(p[i]>=97 && p[i]<=123)
 {
   p[i]=p[i]-32;
 }
 i++;
}
}

void reverse(char *p)
{
int i,j,len=strlen(p);
char ch;
for(i=0,j=len-1;i<j;i++,j--)
{
ch=p[i];
p[i]=p[j];
p[j]=ch;
}
}

void copy(char *p,char *q)
{
while(*q)
{
*p=*q;
q++;
p++;
}
if(*p!=0)
*p=0;
}

void concat(char *p,char *q)
{
int i=0,j=0;
while(p[i])
{
i++;
}
p[i]=32;
i++;
while(q[j])
{
p[i]=q[j];
i++;
j++;
}
p[i]='\0';
}

WRITE A PROGRAMME TO COUNT THE NO OF WORDS IN A STRING

#include<conio.h>
#include<stdio.h>
void main()
{
char s1[50];
int i=0,j,c=0;
clrscr();
printf("enter the string\n");
gets(s1);
while(s1[i])
{
if(s1[i]==32)
 {
  c++;
if(s1[i+1]==32)
{
 j=i+1;
 while(s1[j]==32)
 {
    j++;
    continue;
 }
 i=j;
}
  }
i++;
}
printf("no of words in %s are %d",s1,++c);
getch();
}

WRITE A PROGRAMME TO INVERT UPPERCASE LETTERS TO LOWERCASE LETTERS AND VICE VERSA IN A STRING

#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
int i=0;
clrscr();
printf("enter the string\n");
gets(s1);
while(s1[i])
{
if(s1[i]>='A'&& s1[i]<='Z')
s1[i]=s1[i]+32;
else if(s1[i]>='a' && s1[i]<='z')
s1[i]=s1[i]-32;
i++;
}
puts(s1);
getch();
}

WRITE A PROGRAMME TO COUNT NO OF VOWELS,CONSONANTS AND NO OF DIGITS IN A STRING

#include<conio.h>
#include<stdio.h>
void main()
{
char ar[20];
int v=0,c=0,d=0,i=0;
clrscr();
printf("enter the string\n");
gets(ar);
while(ar[i])
{
if(ar[i]!=32)
{
if(ar[i]>='0'&&ar[i]<='9')
d++;
else if(ar[i]=='a'||ar[i]=='e'||ar[i]=='i'||ar[i]=='o'||ar[i]=='u')
v++;
else
c++;
}
i++;
}
printf("\nno of vowels in %s are-%d",ar,v);
printf("\nno of consonants in %s are-%d",ar,c);
printf("\nno of digits in %s are-%d",ar,d);
getch();
}

WRITE A PROGRAMME TO COPY ONE STRING INTO ANOTHER STRING

#include<conio.h>
#include<stdio.h>
void main()
{
char s1[20],s2[20];
int i=0;
clrscr();
printf("enter the string\n");
gets(s2);
while(s2[i])
{
s1[i]=s2[i];
i++;
}
s1[i]='\0';
printf("\n%s",s1);
getch();
}

//WRITE A PROGRAMME TO READ AND PRINT A STRING USING SCANF,PRINTF,GETS,PUTS AND %S FORMAT SPECIFIER

#include<conio.h>
#include<stdio.h>
void main()
{
char s1[20],s2[20];
clrscr();
printf("enter the first string\n");
//use of scanf with %s to read string
scanf("%s",s1);
printf("%s",s1);

printf("enter the second string\n");
//use of gets and puts to read and display string
fflush(stdin);
gets(s2);
puts(s2);

getch();
}

Wednesday, May 14, 2014

WRITE A PROGRAMME TO INSERT AN ELEMENT 1-AT THE BEGINNING OF AN ARRAY 2-AT THE END OF AN ARRAY 3-AT A PARTICULAR POSITION IN AN ARRAY

/*WRITE A PROGRAMME TO INSERT AN ELEMENT
1-AT THE BEGINNING OF AN ARRAY
2-AT THE END OF AN ARRAY
3-AT A PARTICULAR POSITION IN AN ARRAY
*/

#include<conio.h>
#include<stdio.h>
void main()
{
int ar[10],i,choice,item,n,pos;
clrscr();
printf("enter the limit of array\n");
scanf("%d",&n);
printf("enter the elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("enter the element to be inserted\n");
scanf("%d",&item);
printf("enter the choice\n");
scanf("%d",&choice);
printf("1=INSERT AT THE BEGINING\n2=INSERT AT THE END\n3=INSERT AT PARTICULAR LOCATION\n");
switch(choice)
{
case 1:
for(i=n;i>0;i--)
{
ar[i]=ar[i-1];
}
ar[i]=item;
break;
case 2:
ar[n]=item;
break;
case 3:
printf("enter the position\n");
scanf("%d",&pos);
pos--;
for(i=n;i>pos;i--)
{
ar[i]=ar[i-1];
}
ar[i]=item;
break;
default:
printf("wrong choice");
}
printf("now the elments of array are\n");
for(i=0;i<=n;i++)
{
printf("%d",ar[i]);
}
getch();
}

Thursday, April 3, 2014

PROGRAM TO PRINT THE FREQUENCY OF EACH ELEMENT IN AN ARRAY

//PROGRAM TO PRINT THE FREQUENCY OF EACH ELEMENT IN AN ARRAY

#include<conio.h>
#include<stdio.h>
void main()
{
int a[10],i,c,j,n;
clrscr();
printf("enter the limit of array\n");
scanf("%d",&n);
printf("enetr the elements of array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
c=0;
for(j=0;j<n;j++)
{
if(a[i]==a[j])
{
c++;
}
}
printf("the frequency of element %d at %d index is %d\n",a[i],i,c);
}
getch();
}

PROGRAM TO PRINT THE LOWER TRIANGLE OF A MATRIX

//PROGRAM TO PRINT THE LOWER TRIANGLE OF A MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,n;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
if(row==col)
{
printf("the lower triangular matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j<i||j==i)
{
printf(" %d ",ar[i][j]);
}
}
printf("\n\n");
}
}
else
printf("cant calculate the lower matrix");
getch();
}

PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

//PROGRAM TO PRINT THE UPPER TRIANGLE IN A MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,n;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
if(row==col)
{
printf("the upper triangular matrix\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(j>i||j==i)
{
printf(" %d ",ar[i][j]);
}
else
{
printf("   ");
}
}
printf("\n\n");
}
}
else
printf("cant calculate th e upper matrix");
getch();
}

PROGRAM FOR SUM OF ROW AND COLUMN OF NON SQUARE/SQUARE MATRIX

//PROGRAM FOR SUM OF ROW AND COLUMN OF NON SQUARE/SQUARE MATRIX

#include<stdio.h>
#include<conio.h>
main()
{
 int i,j,k,A[10][10],R_S,C_S,r,c;
 clrscr();
 printf(" ENTER THE SIZE OF A MATRIX \n");
 scanf("%d%d",&r,&c);

 printf("ENTER THE ELEMENT OF A MATRIX \n");
 for(i=0;i<r;i++)
  for(j=0;j<c;j++)
    scanf("%d",&A[i][j]);

 /* Sum of rows */
 for(i=0;i<r;i++)
 {
   R_S=0;
    for(j=0;j<c;j++)
        {
        R_S=R_S+A[i][j];
}
printf("\nSum of %d row is %d",i+1,R_S);
 }

/* Sum of Column */
for(i=0;i<c;i++)
{
        C_S=0;
          for(j=0;j<r;j++)
   {
    C_S=C_S+A[j][i];
           }
   printf("\nSum of %d Col is %d",i+1,C_S);
}

getch();
  }

PROGRAM TO PRINT THE ROW SUM,COLUMN SUM AND DIAGONAL SUM OF A SQUARE MATRIX

//PROGRAM TO PRINT THE ROW SUM,COLUMN SUM AND DIAGONAL SUM OF A SQUARE MATRIX

#include<conio.h>
#include<stdio.h>
#define row 3
#define col 3
void main()
{
int ar[row][col],i,j,r_s,c_s,d_s=0;
clrscr();

printf("enetr the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&ar[i][j]);
}
}
printf(" the elements of array\n");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",ar[i][j]);
}
printf("\n\n");
}
for(i=0;i<row;i++)
{
r_s=0;c_s=0;
for(j=0;j<col;j++)
{
r_s=r_s+ar[i][j];
c_s=c_s+ar[j][i];
if(i==j)
{
d_s=d_s+ar[i][j];
}
}
printf("\nsum of row %d is %d",i,r_s);
printf("\nsum of col %d is %d",i,c_s);
}
printf("\nsum of diagonal is %d",d_s);
getch();
}

PROGRAM TO PRINT THE TRANSPOSE OF A MATRICES

PROGRAM TO PRINT THE TRANSPOSE OF A MATRICES

#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],i,j,r,c;
clrscr();
printf("enter the no of rows\n");
scanf("%d",&r);
printf("enter the no of col\n");
scanf("%d",&c);
printf("enter the matrics\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("the elements of matrics\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}
printf("the transpose of matrics is\n");
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
printf(" %d ",a[j][i]);
printf("\n\n");
}
getch();
}

PROGRAM TO MULTIPLY TWO MATRICES

//PROGRAM TO MULTIPLY TWO MATRICES
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],k,i,j,r1,c1,r2,c2;
clrscr();
printf("enetr the no of rows of first matrics\n");
scanf("%d",&r1);
printf("enter the no of cols of first matrics\n");
scanf("%d",&c1);
printf("enetr the no of rows of second matrics\n");
scanf("%d",&r2);
printf("enter the no of cols of second matrics\n");
scanf("%d",&c2);
printf("enter the elements of first matrics\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}
printf("the elements of first matrics are \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}
printf("enter the elements of second matrics\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
printf("the elements of second matrics are \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf(" %d ",b[i][j]);
printf("\n\n");
}

if(c1==r2)
{
printf("the multiplication of two matrices is\n");
for(i=0;i<r1;i++)
{
 for(j=0;j<c2;j++)
   {
     c[i][j]=0;
      for(k=0;k<c1;k++)
       {
        c[i][j]=c[i][j]+a[i][k]*b[k][j];
       }
     printf(" %d ",c[i][j]);
   }
  printf("\n\n");
}
}
else
printf("multiplication is not possible\n");

getch();
}

//PROGRAM TO ADD TWO MATRICES

//PROGRAM TO ADD TWO MATRICES
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,r1,c1,r2,c2;
clrscr();

printf("enetr the no of rows of first matrics\n");
scanf("%d",&r1);
printf("enter the no of cols of first matrics\n");
scanf("%d",&c1);
printf("enetr the no of rows of second matrics\n");
scanf("%d",&r2);
printf("enter the no of cols of second matrics\n");
scanf("%d",&c2);

printf("enter the elements of first matrics\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}

printf("the elements of first matrics are \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf(" %d ",a[i][j]);
printf("\n\n");
}

printf("enter the elements of second matrics\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}

printf("the elements of second matrics are \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf(" %d ",b[i][j]);
printf("\n\n");
}

if(r1==r2&&c1==c2)
{
printf("the addition of two matrices is\n");
for(i=0;i<r1;i++)
{
  for(j=0;j<c1;j++)
    {
     c[i][j]=a[i][j]+b[i][j];
    }
 printf(" %d ",C[i][j]);}
}
else
printf("addition is not possible\n");
getch();
}

PROGRAM TO ADD 10 TO EACH ELEMENT OF A 2-D ARRAY AND PRINT IT IN MATRIX FORM

//PROGRAM TO ADD 10 TO EACH ELEMENT OF A 2-D ARRAY AND PRINT IT IN MATRIX FORM

#include<conio.h>
#include<stdio.h>
void main()
{
int ar[10][10],i,j,row,col;
clrscr();
printf("enetr the no of rows\n");
scanf("%d",&row);
printf("enter the no of cols\n");
scanf("%d",&col);
printf("enter the elements of 2d array\n");
for(i=0;i<row;i++)
{
  for(j=0;j<col;j++)
  {
    scanf("%d",&ar[i][j]);
  }
}
printf("the elements of 2d array are\n");
for(i=0;i<row;i++)
{
   for(j=0;j<col;j++)
   {
     printf(" %d ",ar[i][j]+10);
   }
printf("\n\n");
}
getch();
}

PROGRAM TO CONVERT A DECIMAL NUMBER INTO BINARY NUMBER(NUMBER SHOULD BE A WHOLE NUMBER)

//PROGRAM TO CONVERT A DECIMAL NUMBER INTO BINARY NUMBER(NUMBER SHOULD BE A WHOLE NUMBER)

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],n,i,t;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
t=n;
for(i=0;n>=1;i++)
{
a[i]=n%2;
n=n/2;
}
printf("the binary representation of %d is ",t);
for(i=i-1;i>=0;i--)
printf("%d",a[i]);
getch();

PROGRAMME TO SORT AN ARRAY

//PROGRAMME TO SORT AN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],t,i,j,m;
clrscr();
printf("enter the limit of first array\n");
scanf("%d",&m);
printf("enter the elements of array\n");
for(i=0;i<m;i++)
{scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
  for(j=0;j<m-1-i;j++)
  {
   if(a[j]>a[j+1])
      {
       t=a[j];
       a[j]=a[j+1];
       a[j+1]=t;
      }
  }
}
printf("the elements of array in sorted order are\n");
for(i=0;i<m;i++)
{
printf("%d\n",a[i]);
}
getch();
}

PROGRAM TO MERGE TWO ARRAYS PROVIDED THAT ARRAYS ARE NOT ENTERED IN SORTED ORDER. A MERGED ARRAY CONTAINS ELEMENTS IN SORTED ORDER

//PROGRAM TO MERGE TWO ARRAYS PROVIDED THAT ARRAYS ARE NOT ENTERED IN SORTED ORDER. A MERGED ARRAY CONTAINS ELEMENTS IN SORTED ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[10],t,i,j,k,l,n,m;
clrscr();
printf("enter the limit of first array\n");
scanf("%d",&m);
printf("enter the limit of second array\n");
scanf("%d",&n);
printf("enter the elements of array1\n");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}

for(i=0;i<m;i++)
{
 for(j=0;j<m-1-i;j++)
  {
   if(a[j]>a[j+1])
     {
      t=a[j];
      a[j]=a[j+1];
      a[j+1]=t;
     }
  }
}

printf("the elements of array1\n");
for(i=0;i<m;i++)
{
printf("%d\n",a[i]);
}

printf("enter the elements of array2\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}


for(i=0;i<n;i++)
{
 for(j=0;j<n-1-i;j++)
  {
   if(b[j]>b[j+1])
   {
     t=b[j];
     b[j]=b[j+1];
     b[j+1]=t;
   }
  }
}


printf("the elements of array2\n");
for(i=0;i<n;i++)
{
 printf("%d\n",b[i]);
}

for(i=0,j=0,k=0;i<m&&j<n;)
{
  if(a[i]<b[j])
    {
      c[k]=a[i];
      i++;
      k++;
    }
  else if(a[i]>b[j])
    {
     c[k]=b[j];
     k++;
     j++;
    }
  else
    {
     c[k]=a[i];
     i++;
     j++;
     k++;
    }
}


for(;i<m;i++)
{
  c[k]=a[i];
  k++;
}

for(;j<n;j++)
{
  c[k]=b[j];
  k++;
}

printf("elements of third array are\n");
for(i=0;i<k;i++)
printf("%d\n",c[i]);
getch();
}

PROGRAM TO ADD TWO UNEQUAL SIZED ARRAYS

//PROGRAM TO ADD TWO UNEQUAL SIZED ARRAYS

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10]={0},b[10]={0},c[10]={0},i,l,n,m;
//PARTIAL INITIALIZATION  WILL SET ALL INDEX BY 0 OF ARRAY A, B & C
clrscr();
printf("enter the limit of first array\n");
scanf("%d",&m);
printf("enter the limit of second array\n");
scanf("%d",&n);
printf("enter the elements of array1\n");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("enter the elements of array2\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}

if(m>n)
{
l=m;
for(i=0;i<m;i++)
{
c[i]=a[i]+b[i];
}
}
else
{
l=n;
for(i=0;i<n;i++)
{
c[i]=a[i]+b[i];
}
}
printf("elements of third array are\n");
for(i=0;i<l;i++)
printf("%d\n",c[i]);
getch();
}

PROGRAM TO ADD TWO EQUAL SIZED ARRAY

//PROGRAM TO ADD TWO EQUAL SIZED ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[10],i,m;
clrscr();
printf("enter the limit for array\n");
scanf("%d",&m);
printf("enter the elements of array1 and array2\n");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
scanf("%d",&b[i]);
c[i]=a[i]+b[i];
}
printf("the elements of third array are\n");
for(i=0;i<m;i++)
printf("%d\n",c[i]);
getch();
}

PROGRAM TO SEARCH AN ELEMENT IN AN ARRAY

//PROGRAM TO SEARCH AN ELEMENT IN AN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10]={0},flag=0,i,item,n;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the value to be searched\n");
scanf("%d",&item);
printf("enter the elements\n");

for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
for(i=0;i<n;i++)
{
if(ar[i]==item)
{
flag=1;
printf("element %d found at index %d",item,i);
break;
}
}
if(flag==0)
printf("element not found");
getch();
}

PROGRAM TO FIND MIN AND MAX ELEMENT IN AN ARRAY

//PROGRAM TO FIND MIN AND MAX ELEMENT IN AN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10]={0},min,max,i,n,j,temp;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");

for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
min=ar[0];
max=ar[0];
for(i=0;i<n;i++)
{
if(ar[i]>max)
max=ar[i];
if(ar[i]<min)
min=ar[i];
}
printf("max=%d min=%d",max,min);
getch();
}

PROGRAM TO REVERSE AN ARRAY WITHOUT USING ANOTHER ARRAY

//PROGRAM TO REVERSE AN ARRAY WITHOUT USING ANOTHER ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],i,n,j,temp;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
printf("reverse of array is\n");
for(i=0,j=n-1;i<j;i++,j--)
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
for(i=0;i<n;i++)
{
printf("\n%d",ar[i]);
}
getch();
}

PROGRAMME TO PRINT THE ELEMNTS OF AN ARRAY IN REVERSE ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],i,n,s=0,c=0,avg;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
i--;
printf("reverse of array is\n");
for(;i>=0;i--)
printf("%d\n",ar[i]);
getch();
}

PROGRAM TO PRINT THE ELEMENTS OF AN ARRAY IN REVERSE ORDER

//PROGRAM TO PRINT THE ELEMENTS OF AN ARRAY IN REVERSE ORDER

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],i,n,s=0,c=0,avg;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
i--;
printf("reverse of array is\n");
for(;i>=0;i--)
printf("%d\n",ar[i]);
getch();
}

PROGRAMME TO PRINT ALL THE ELEMENTS GRATER THAN THE AVERAGE OF ALL ELEMENTS AND ALSO PRINT THE TOTAL COUNT

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],i,n,s=0,c=0;
int avg;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
s=s+ar[i];
}
avg=s/n;
printf("average is %d",avg);
for(i=0;i<n;i++)
{
if(ar[i]>avg)
{
printf("\n%d is grater than avg",ar[i]);
c++;
}
}
printf("\ntotal elemnts grater than avg are %d",c);
getch();
}

PROGRAMME TO FIND THE SUM OF ALL ELEMENTS OF AN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
int ar[10],i,n,s=0;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
s=s+ar[i];
}
printf("the sum is %d",s);
getch();
}

Friday, March 7, 2014

WRITE A FUNCTION TO CALCULATE THE BINARY EQUIVALENT OF A NUMBER WITH DECIMAL BASE USING RECURSION

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int binary(int*,int,int);
int num,a[10],i=0;
clrscr();
printf("enter the number\n");
scanf("%d",&num);
i=binary(a,num,i);
i--;
printf("the binary equivalennt of %d is ",num);
for(;i>=0;i--)
printf("%d",a[i]);
getch();
}

int binary(int*p,int n,int i)
{
if(n>=1)
{
*(p+i)=n%2;
i++;
binary(p,n/2,i);
}
else
return(i);
}

WRITE A FUNCTION TO CALCULATE THE BINARY EQUIVALENT OF A NUMBER IN DECIMAL BASE

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int binary(int*,int);
int num,a[10],i;
clrscr();
printf("enter the number\n");
scanf("%d",&num);
i=binary(a,num);
i--;
printf("the binary equivalennt of %d is ",num);
for(;i>=0;i--)
printf("%d",a[i]);
getch();
}

int binary(int*p,int n)
{
int i;
for(i=0;n>=1;i++)
{
*(p+i)=n%2;
n=n/2;
}
return(i);
}

WRITE A FUNCTION TO CALCULATE THE SUM OF DIGITS OF A NUMBER USING RECURSION

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int sum(int);
int n,s;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
s=sum(n);
printf("the sum of digits of %d is %d",n,s);
getch();
}

int sum(int n)
{
int s=0;
if(n>0)
{
s=s+n%10;
return(s+sum(n/10));
}
else
return(0);
}

WRITE A FUNCTION TO CALCULATE THE SUM OF DIGITS OF A NUMBER

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int sum(int);
int n,s;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
s=sum(n);
printf("the sum of digits of %d is %d",n,s);
getch();
}

int sum(int n)
{
int s=0;
while(n>0)
{
s=s+n%10;
n=n/10;
}
return(s);
}

WRITE A FUNCTION POWER TO CALCULATE A FLOATING POINT NUMBER TO BE RAISED TO AN INTEGER POWER

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void power(float,int);
int p;
float n;
clrscr();
printf("enter the number\n");
scanf("%f",&n);
printf("\nenter the power\n");
scanf("%d",&p);
power(n,p);
getch();
}
void power(float n,int p)
{
float r=1;
int i;
for(i=1;i<=p;i++)
{
r=r*n;
}
printf("%f to the power %d is %f",n,p,r);
}

WRITE A FUNCTION TO CALCULATE AND DISPLAY REAL ROOTS OF A QUADRATIC EQUATION

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void root(int,int,int);
int a,b,c,d;
clrscr();
printf("enter the values of constants\n");
scanf("%d%d%d",&a,&b,&c);
d=(b*b-4*a*c);
if(d>0)
{
printf("the real roots of equation are\n");
root(a,b,d);
}
else
printf("roots are imaginary");
getch();
}
void root(int a,int b,int d)
{
int r1,r2;
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("r1=%d r2=%d",r1,r2);
}

WRITE A FUNCTION TO CALCULATE FACTORIAL OF A NUMBER USING RECURSION

#include<conio.h>
#include<stdio.h>
void main()
{
int fact(int);
int n,r;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
r=fact(n);
printf("the factorial of %d is %d",n,r);
getch();
}

int fact(int num)
{
if(num==1||num==0)
return(1);
else
return(num*fact(num-1));
}

WRITE A FUNCTION TO CONVERT A LOWERCASE CHARACTER TO UPPERCASE

#include<conio.h>
#include<stdio.h>
void main()
{
char convert(char);
char ch,r;
clrscr();
printf("enter the character\n");
scanf("%c",&ch);
r=convert(ch);
printf("the uppercase conversion of %c is %c",ch,r);
getch();
}

char convert(char ch)
{
return (ch-32);
}

WRITE A FUNCTION TO CALCULATE FACTORIAL OF A NUMBER

#include<conio.h>
#include<stdio.h>
void main()
{
int fact(int);
int n,r;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
r=fact(n);
printf(" %d! is %d",n,r);
getch();
}

int fact(int n)
{
int f=1,i;
for(i=1;i<=n;i++)
f=f*i;
return f;
}

WRITE A FUNCTION TO FIND LARGEST OF TWO VALUES AND PRINT THE RESULT IN CALLING FUNCTION

#include<conio.h>
#include<stdio.h>
void main()
{
int large(int,int);
int a,b,r;
clrscr();
printf("enter the numbers\n");
scanf("%d%d",&a,&b);
r=large(a,b);
printf("the largest value is %d",r);
getch();
}

int large(int a,int b)
{
if(a>b)
return a;
else
return b;
}

WRITE A FUNCTION THAT ACCEPTS MARKS OBTAINED BY A STUDENT IN 3 SUBJECTS AND RETURNS THE AVERAGE AND PERCENTAGE OF THE MARKS

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void cal(int*,float*,float*);
int ar[3],i;
float avg,per;
clrscr();
printf("enter the marks out of 50\n");
for(i=0;i<3;i++)
{
scanf("%d",&ar[i]);
}
cal(ar,&avg,&per);
printf("\nthe avg of marks is %f",avg);
printf("\nthe percentage of marks is %f",per);
getch();
}

void cal(int *a,float *avg,float*per)
{
int i,s=0;
for(i=0;i<3;i++)
{
s=s+*(a+i);
}
*avg=s/3;
*per=s*100/150;
}




WRITE A FUNCTION THAT ACCEPTS 5 INTEGERS AND RETURNS SUM,AVERAGE AND STANDARD DEVIATION OF TEHESE NUMBERS

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void calculate(int[],int,int*,float*,float*);
int ar[10],i,s=0,n;
float sd=0,avg;
clrscr();
printf("enter the limit of array\n");
scanf("%d",&n);
printf("enter the elements of an array\n");
for(i=0;i<n;i++)
scanf("%d",&ar[i]);
calculate(ar,n,&s,&avg,&sd);
printf("the sum of numbers is %d\n",s);
printf("\nthe average of numbers is %f\n",avg);
printf("the standard deviation is %f\n",sd);
getch();
}

void calculate(int a[],int n,int *sum,float*avg,float*s_d)
{
int i;
float t;
for(i=0;i<n;i++)
{
*sum=*sum+a[i];
}
*avg=*sum/n;
for(i=0;i<n;i++)
{
t=*avg-a[i];
*s_d=*s_d+pow(t,2);
}
*s_d=*s_d/(n-1);
*s_d=sqrt(*s_d);
}



WRITE A FUNCTION TO FIND VOLUME OF A SPHERE

#include<conio.h>
#include<stdio.h>
#define PI 3.14
void main()
{
float volume(int);
int r;
float vol;
clrscr();
printf("enter the radius\n");
scanf("%d",&r);
vol=volume(r);
printf("the volume of sphere is %f",vol);
getch();
}

float volume(int r)
{
float v;
v=(4*PI*r*r*r)/3;
return(v);
}

WRITE A FUNCTION TO FIND AREA OF A SPHERE

#include<conio.h>
#include<stdio.h>
#define PI 3.14
void main()
{
void area(int);
int r;
clrscr();
printf("enter the radius\n");
scanf("%d",&r);
area(r);
getch();
}

void area(int r)
{
float a;
a=4*PI*r*r;
printf("the area of sphere is %f",a);
}

WRITE A FUNCTION POWER THAT COMPUTE X RAISED TO THE POWER Y AND RETURN DOUBLE TYPE VALUE

#include<conio.h>
#include<stdio.h>
void main()
{
double power(int,int);
int n,p;
double r;
clrscr();
printf("enter the no and power\n");
scanf("%d%d",&n,&p);
r=power(n,p);
printf("%d to the power %d is %lf",n,p,r);
getch();
}

double power(int n,int p)
{
//double r=1;
int i;
//for(i=1;i<=p;i++)
for(i=1;i<p;i++)
{
//r=r*n;
n=n*n;
}
//return(r);
return(n);
}

WRITE A FUNCTION TO CALCULATE SUM OF FIRST N INTEGERS

#include<conio.h>
#include<stdio.h>
void main()
{
void sum(int);
int n;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
sum(n);
getch();
}

void sum(int n)
{
int i,s=0;
for(i=0;i<=n;i++)
s=s+i;
printf("the sum of first %d nos is %d",n,s);
}

WRITE A FUNCTION WHICH ACCEPTS TWO INTEGERS AND DETERMINE THE LARGEST VALUE WHICH IS THEN DISPLAYED IN FUNCTION ITSELF

#include<conio.h>
#include<stdio.h>
void main()
{
void min_max(int,int);
int a,b;
clrscr();
printf("enter two nos\n");
scanf("%d%d",&a,&b);
min_max(a,b);
getch();
}

void min_max(int a,int b)
{
if(a>b)
printf("a= %d is grater than b= %d",a,b);
else
printf("b= %d is grater than a= %d",b,a);
}