C

Friday, 18 August 2017

Program To Perform Logical Operator

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(b>c))
printf("\na is greater than b =%d",a);
else
printf("\nb is greater than a =%d",b);
if(a>c)
printf("\na is greater value than c =%d",a);
else
printf("\nc is greater value than a =%d",c);
if((a==b)||(a==c))
printf("\na value is equal to b");
else
printf("\nvalues are not equal");
getch();
}                 

Program To Perform Relational Operator

#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z;
clrscr();
printf("Enter the values of x,y and z\n");
scanf("%d%d%d,",&x,&y,&z);
if(x==y)
printf("\nBoth the values are same =%d",x,y);
if(x>y)
printf("\nThe value of x is greater =%d",x);
else
printf("\nThe value of y is greater =%d",y);
if(y!=z)
printf("\nThe value of y is not equal to =%d",y);
getch();
}

Friday, 4 August 2017

SWAPPING OF TWO VALUES WITHOUT USING THIRD VARIABLE

#include<stdio.h>
#include<conio.h>
main()
{
int a=8, b=12;
clrscr();
printf("Before swap of two numbers a=%d b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swap of numbers a=%d b=%d",a,b);
getch();
}

Thursday, 27 July 2017

PROGRAM TO FIND GEOMETRIC MEAN

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    int a[10],n,i;
    double sum=0, gm;
    clrscr();
    printf("Enter the total no. of elements");
    scanf("%d",&n);
    printf("Enter the elements\n");
    for(i=0;i<n;i++)
       scanf("%d",&a[i]);
    for(i=0;i<n;i++)
       sum =sum+(log10(a[i]));
    gm=exp(sum/n*log(10));
    printf("Geometric mean is %f",gm);
    getch();
}

Sunday, 16 July 2017

PROGRAM TO FIND ARITHMETIC MEAN

#include<stdio.h>
#include<conio.h>
void main()
{
   int a[50],n,i,s;
   float mean;
   clrscr();
   printf("enter how many terms u want to enter\n");
   scanf("%d",&n);
   printf("enter %d terms\n",n);
   for(i=0;i<n;i++)
     scanf("%d",&a[i]);
     s=0;
     for(i=0;i<n;i++)
     s+=a[i];
     mean=s/n;
     printf("mean is %f",mean);
     getch();

}

Saturday, 8 July 2017

Program to read name of a employee, employee number and salary from the keyboard and writes same to binary file

#include<stdio.h>
struct employee
{
          int eno,salary;
          char name[20];
}        
main()
{

          struct employee e;
          char ans;
          FILE *fp;
          fp=fopen("file9.out","wb");
          if(fp==NULL)
          {
                   printf("Error in file opening");
                   exit(0);
          }
          do
          {
                   printf("\nEmployee No.");
                   scanf("%d",&e.eno);
                   printf("\nName :");
                   scanf("%s",&e.name);
                   printf("\nSalary");
                   scanf("%d",&e.salary);
                   fwrite(&e,sizeof(e),1,fp);
                   printf("\nDo you want to add more records y/n");
                   ans=getch();
          }while(ans !='n');
          fclose(fp);

}

Program to demonstrate pointer to structure

#include<stdio.h>
main()
{
          struct student
          {
                   int roll;
                   char name[20];
                   int age;
                   char class[8];
          };        
          struct student s,*ptr;
          ptr=&s;
          printf("Enter the student record\n");
          printf("Roll no. :");
          scanf("%d",&ptr->roll);
          printf("Name :");
          scanf("%s",&ptr->name);
          printf("Age:");
          scanf("%d",&ptr->age);
          printf("Class :");
          scanf("%s",&ptr->class);
          printf("\n Record details are\n");
          printf("Roll no: %d\n",ptr->roll);
          printf("Name: %s\n",ptr->name);
          printf("Age: %d\n",ptr->age);
          printf("Class : %s\n",ptr->class);

}

Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...