Saturday, 18 July 2020

fseek demo program

Q : Write a file statement to place a file pointer (fp) at the beginning of the record number (say R), where record size is B bytes.


Answer : 

#include<stdio.h>

#include<conio.h>

/*============================

     Girfa Student Help

     fseek demo

==============================*/

Friday, 17 July 2020

Structure for Employee

A programmer wants to use two variables session and info. Variable session can take three values (morning, afternoon, evening) ly. Using variable info, the programmer wants to access information empname and empid of 30 employees. Name the appropriate data type used for each variable session and info and declare the variables.

Answer : 



#include<stdio.h>
#include<conio.h>
/*============================
     Girfa Student Help
     structure data type
==============================*/

Difference and similarity between continue and break | C Language

Write down one similarity and one dissimilarity between break and continue statements.


Similarity


The main difference between break and continue statements in C language is that a break origins the innermost enclosing loop or switch to be exited immediately. Whereas, the continue statement origins the next iteration of the enclosing for, while, or do loop to begin. The continue statement in while and do loops takes the control to the loop's test-condition immediately, whereas in the for loop it takes the control to the increment step of the loop.

Thursday, 16 July 2020

Min Max find program 2d-array using function | C Language

Q : Write a function fnmat() which takes matrix, m, n as arguments where matrix is of size mXn with m as rows and n as columns. Function should return the maximum and minimum elements of the matrix. Elements of matrix are of integer type.


Answer : 


#include<stdio.h>
#include<conio.h>
#define ROW 5
#define COL 5
/*============================
     Girfa Student Help
     Find max,min 2d-array using function
==============================*/
void fnmat(int ar[ROW][COL],int,int);
void main()
{
     int ar[ROW][COL],r,c,i,j;
     clrscr();
     printf("Enter row & columns for array entry>> ");
     scanf("%d%d",&r,&c);
     if(r>ROW)
           printf("Given row is greater than row capacity of %d",ROW);
     else if(c>COL)
           printf("Given column is greater than column capacity of %d",COL);
     else
     {
           for(i=0;i<r;i++)
           {
                for(j=0;j<c;j++)
                {
                     printf("Enter number for ar[%d][%d]>> ",i+1,j+1);
                     scanf("%d",&ar[i][j]);
                }
           }
           clrscr();
           /* Printing array */
           for(i=0;i<r;i++)
           {
                for(j=0;j<c;j++)
                     printf("\t%d",ar[i][j]);
                printf("\n");
           }
           fnmat(ar,i,j);
     }
     getch();
}
void fnmat(int ar[ROW][COL],int r,int c)
{
     int i,j,min,max;
     min=max=ar[0][0];
     for(i=0;i<r;i++)
     {
           for(j=0;j<c;j++)
           {
                if(min>ar[i][j])
                     min=ar[i][j];
                else
                     max=ar[i][j];
           }
     }
     printf("\n\n\tMix=%d\n\tMax=%d",min,max);
}