Pages

Tuesday, 5 March 2019

Program to illustrate pointer arithmetic

Program to illustrate pointer arithmetic without increment operator

#include <stdio.h>
void main()
{
   int a[5]={10,20,30,40,50};
   int *p;
   int *q;
   p=&a[1];
   q=&a[4];
   printf("\n value is  %d",(*p + *q));  
}

output:


Program to illustrate pointer arithmetic with increment operator

#include <stdio.h>
void main()
{
   int a[5]={10,20,30,40,50};
   int *p;
   int *q;
   p=&a[1];
   q=&a[4];
   p++;
   printf("\n value is  %d",(*p + *q));
   q++;
   printf("\n value is  %d",(*p + *q));
}
output:

 

Program on single and double pointer

Program on single and double pointer

#include <stdio.h>
void main()
{
   int x=4,y,z;
   int *sp;
   int **dp;
   printf("\n x value is %d",x);
   printf("\n x address is %p",&x);  
   sp=&x; 
   printf("\n y value is %p",sp);
   printf("\n y address is %p",&sp);  
   dp=&sp;
   printf("\n z value is %p",dp);
   printf("\n z address is %p",&dp);  
   *sp+=1;
   y=*sp;  
   printf("\n y value is %d",y);
   **dp+=3;
   z=**dp;
   printf("\n z value is %d",z);
   printf("\n value of x+y+z =%d",(x+y+z));
}
output:

Program to illustrate single pointer and double pointer

Program to illustrate pointer variable using single pointer
#include <stdio.h>
int main()
{
   int x=50,*y;
   printf("\n x value is %d",x);
   printf("\n x address  is %p",&x);
   y=&x;
   printf("\n y value is %p",y);
   printf("\n y address is %p",&y);
   printf("\n y value is %d",*y);
   return 0;
}

output:

Program to illustrate pointer variable using double pointer
#include <stdio.h>
void main()
{
   int x=10,*y;
   int **z;
   printf("\n x value is %d",x);
   printf("\n x address is %p",&x);  
   y=&x; 
   printf("\n y value is %p",y);
   printf("\n y address is %p",&y);  
   z=&y;
   printf("\n z value is %p",z);
   printf("\n z address is %p",&z);  
   printf("\n y value is %d",*y);
   printf("\n z value is %d",**z);
}

output:

Program to illustrate transpose of a matrix

Program to illustrate transpose of a matrix
#include <stdio.h>
  void main()
    {
       int row, col, i, j, first[10][10], trans[10][10];
       printf("Enter the number of rows and columns of first matrix\n");
       scanf("%d%d", &row, &col);
       printf("Enter the %d elements of first matrix\n",row * col);
       for (i = 0; i < row; i++)
          {
          for (j = 0; j < col; j++)
            {
             scanf("%d", &first[i][j]);
            }
          }
       printf("\nFirst matrix :\n");
       for (i = 0; i < row; i++)
         {
          for (j = 0; j < col; j++)
            {
             printf("%d\t", first[i][j]);
            }
           printf("\n");
         }
        for (i = 0; i < row; i++)
        {
          for (j = 0 ; j < col; j++)
          {
             trans[i][j] = first[j][i];
          }
          printf("\n");
       }
       printf("\n Transpose of first matrix\n ");
       for (i = 0; i < row; i++)
         {
          for (j = 0; j < col; j++)
            {
             printf("%d\t", trans[i][j]);
            }
           printf("\n");
         }
      
  }

output:

Monday, 4 March 2019

Program to illustrate n number of students records using structure

Program to illustrate n number of students records using structure 


#include <stdio.h>
struct student
{
   // defining a structure
   char name[33];
   int sno,sub1,sub2;
   float tot;
} s[11];

int main()
{
   int i,n;
   printf("\n Enter the number of students information :");
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {
    printf("\n Enter student number :");
    scanf("%d",&s[i].sno);
    printf("\n Enter student name :");
    scanf("%s",s[i].name);
    printf("\n Enter student mark in subject1 :");
    scanf("%d",&s[i].sub1);
    printf("\n Enter student mark in subject2 :");
    scanf("%d",&s[i].sub2);
   }
   printf("\n **** Student Details  **** :");
   printf("\n SNO  ---   SNAME  ---  SUB1  ---  SUB2   ---   TOTAL");   
  for(i=1;i<=n;i++)
   {
    s[i].tot = s[i].sub1 + s[i].sub2;
    printf("\n %d   ---    %s    ---    %d    ---     %d    ---   %f ",s[i].sno,s[i].name,s[i].sub1,s[i].sub2,s[i].tot);
   }
   
  return 0;
}


output:

Sunday, 3 March 2019

Program to illustrate student information using union

Program to illustrate student information using union

#include <stdio.h>
union student
{
   // defining union member variables
   char name[33];
   int sno,sub1,sub2;
   float tot;
} s;

int main()
{
   printf("\n Enter student number :");
   scanf("%d",&s.sno);
   printf("\n Enter student name :");
   scanf("%s",s.name);
   printf("\n Enter student mark in subject1 :");
   scanf("%d",&s.sub1);
   printf("\n Enter student mark in subject2 :");
   scanf("%d",&s.sub2);
   s.tot = s.sub1 + s.sub2;
   printf("\n Total marks = %f ",s.tot);
   return 0;
}

output:

Program to illustrate student information using structure

 Program to illustrate student information using structure

#include <stdio.h>
struct student
{
   // defining a structure
   char name[33];
   int sno,sub1,sub2;
   float tot;
} s;

int main()
{
   printf("\n Enter student number :");
   scanf("%d",&s.sno);
   printf("\n Enter student name :");
   scanf("%s",s.name);
   printf("\n Enter student mark in subject1 :");
   scanf("%d",&s.sub1);
   printf("\n Enter student mark in subject2 :");
   scanf("%d",&s.sub2);
   s.tot = s.sub1 + s.sub2;
   printf("\n Total marks = %f ",s.tot);
   return 0;
}

output:


Program to find number of bytes allocated to structure and union

Program to find number of bytes allocated to structure and union

#include <stdio.h>
union unionJob
{
   //defining a union
   char name[3];
   float salary;
   int workerNo;
} uJob;

struct structJob
{
   // defining a structure
   char name[3];
   float salary;
   int workerNo;
} sJob;

int main()
{
   printf("size of union = %ld bytes", sizeof(uJob));
   printf("\nsize of structure = %ld bytes", sizeof(sJob));
   return 0;
}

output:


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...