Skip to main content

Search This Blog

matrix multiplication in c using functions and pointers

 #include <stdio.h> #define ROWS 3 #define COLS 3 void matrixMultiply(int *mat1, int *mat2, int *result, int rows1, int cols1, int cols2) {     int i, j, k;     // Multiplying matrices     for (i = 0; i < rows1; i++) {         for (j = 0; j < cols2; j++) {             *(result + i * cols2 + j) = 0;             for (k = 0; k < cols1; k++) {                 *(result + i * cols2 + j) += *(mat1 + i * cols1 + k) * *(mat2 + k * cols2 + j);             }         }     } } void displayMatrix(int *mat, int rows, int cols) {     int i, j;     // Displaying matrix     for (i = 0; i < rows; i++) {         for (j = 0; j < cols; j++) {             printf("%d\t", *(mat + i * cols + j));         }         printf("\n");     } } int main() {     int mat1[ROWS][COLS] = {{1, 2, 3},                             {4, 5, 6},                             {7, 8, 9}};     int mat2[ROWS][COLS] = {{9, 8, 7},                             {6, 5, 4},                             {

Write and explain the following types of functions with the help of an example program for each (i) Function with no arguments and no return value. (ii) Function with arguments and no return value

hello

Write and explain the following types of functions with the help of an example program for each 
(i) Function with no arguments and no return value.
(ii) Function with arguments and no return value.

ANS-
  
1: Function with no arguments and no return value:

function with no arguments and no return value

OUTPUT

             function with no arguments and no return value.

In this type the function has no arguments, it doesn't receive any data from the calling function.
Similarly it doesn't return any value, the calling function doesn't receive any data from called function. 
So there's no digital communication between calling function and called function.
#include<stdio.h>
#include<conio.h>
void sum();
void main()
{
  
    clrscr();
    sum();
    getch();
}
void sum()
{
    int a,b;
    printf(”Enter any two numbers:”);
    scanf("%d%d",&a,&b);
    printf(”sum= %d”,a+b);
}
  • In this function no return and no argument means create sum function.
  • no any return type, void is no return type data type.
  •  all processing is done inside of sum function body because no argument type means no any value return  then input inside of function, declare scanf() in inside of function.
  • no return any value then defined print any value inside of function. 
  • void main (int a, int b) is called argument then not valid in this type function because no argument .
  • return (a); is return value is not valid in this concept.
  • all kind of processing inside of fuction and only call in main function. 

2. Function with arguments and no return value:


function with arguments and no return value.

OUTPUT

function with arguments and no return value.


In this type the function has some arguments, it receives data from the calling function. But it does not return any value, the calling function does not receive any data from the called function. 


#include<stdio.h>
#include<conio.h>
void main()
{
    void sum(int,int);
    int a,b,s;
    clrscr();
    printf(”Enter any two numbers :”);
    scanf("%d%d",&a,&b);
    sum(a,b);
    getch();
}
void sum(int x,int y)
{
    printf(”sum= %d”,x+y);
}

  • Here x, y are formal argument and a,b are actual arguments.
  • In this question argument with no return type we see function declaration, the argument are formal but when value are passed (a, b ) to the function call, they are actual argument a and b. 
  • In this function is all processing in main function and print other function.
  • we can see program defined two function, first function  is main function and second function  is user defined function sum.
  • we can see sum function passing parameter (argument) is x and y is formal argument but we can see main function passing argument  sum function a and b .actual argument.
  • sum function get a argument to value and print value.

  • First point value processing inside in main function.
  • and call sum function in main and pass argument in sum function and get value sum function and print a value. 




Comments

Popular posts from this blog

Write a C program (use a switch statement for selection) to add or subtract 2 matrices having order 3 x 3, depending upon the choice made by the user

Write a C program (use a switch statement for selection) to add or subtract 2 matrices having order 3 x 3, depending upon the choice made by the user. MCS-011 : PROBLEM SOLVING AND   PROGRAMMING (June, 2017) c program for matrix operations using switch case, c program for addition and subtraction of two matrices, algorithm for matrix addition in c program #include <stdio.h> #include<conio.h> void main() {     int first_matrix[3][3], second_matrix[3][3], sub_of_two_matrix[3][3],sum_of_two_matrix[3][3], i, j;      int oprater;      clrscr(); //Enter First Matrix      printf("\nEnter elements of 1st matrix:\n");     for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) {     printf("Enter element a%d%d: ", i + 1, j + 1);     scanf("%d", &first_matrix[i][j]); } //Enter Second Matrix      printf("Enter elements of 2nd matrix:\n");     for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) {     printf("Enter element

Bcsl-043 java sem4

Ignou question paper java java Java Solution BCSL 43 dec2016 solution Video BCSL 43 june2016 Solution Video BCSL 43 dec2015 Solution Video BCSL 43 june2015 Solution video BCSL 43 dec2014 Solution Video BCSL 43 june2014 Solution Video BCSL 43 dec2013 Solution Video BCSL43 june2013 Solution Video Dec2016  1.Write a Java program to create an applet to find the simple interest on a given amount, rate of interest and duration. Use proper GUI components in your program. import java.util.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; /* */ public class simpleinterest extends Applet{ Label l1,l2,l3,l4; TextField t1,t2,t3; Button b1; Image picture; public void init(){ picture = getImage(getCodeBase(),"20160613_091125.jpg"); l1=new Label("Enter the Amount "); l2=new Label("Enter the Rate "); l3=new Label("Enter interest Duration :"); l4=new Label(&

Contact Form

Name

Email *

Message *