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);
}


POW function | C Language

Q : Write a function fnpow() in C to compute xy where x is float and y is integer. Function will return the result and takes x, y as arguments.

Answer :

#include<stdio.h>
#include<conio.h>
/*============================
     Girfa Student Help
     User defined pow function
==============================*/

Wednesday, 15 July 2020

Difference between Union & Structure


SN.
Structure
Union
1
Struct keyword is used to make structure variable
Union  keyword is used to make structure variable
2
Structure is user defined data type which is used frequently to represent real word data type presentation.
Union is also a user defined data type which is used to achieve specific need.
3
Structure allocates memory for its all member.
Union allocates memory only for the biggest data member.
4
All member data can be hold at same time in a structure variable.
Only one data from member can be hold at a time.
5
Several members can be initialized at ones.
Only first member can be initialized.


Tuesday, 14 July 2020

File writing program append mode using Command Line Argument

Q : Write a program using command line parameters to append one text file to another text file.?


Answer : 



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(int argc,char *argv[])
{
     FILE *infile,*outfi