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 a C program to perform input/output of all basic data types.
Write a C program to enter two numbers and find their sum.
#include 

int main()
{
    int num1, num2, sum;
    
    /*
     * Read two numbers from user
     */
    printf("Enter first number: ");
    scanf("%d", &num1);
    printf("Enter second number:");
    scanf("%d", &num2);
    
    /* Adding both number is simple and fundamental */
    sum = num1 + num2;
    
    /* Prints the sum of two numbers */
    printf("Sum of %d and %d = %d", num1, num2, sum);
    
    return 0;
}


Q. write calculator in c.

#include
#include
int main(void)
{
	float a,b;
	char sign;
	printf("Press 'q' to quit\n");
	printf("Enter any number :");
	scanf("%f",&a);
	do{
		printf("Enter any operator :");
		scanf("%s",&sign);
		printf("Enter any number :");
		scanf("%f",&b);
		switch(sign){
			case'+':
				a=a+b;
				printf("Result :%.2Lf\n",a);
				break;
				case'-':
					a=a-b;
					printf("Result :%.2f\n",a);
					break;
					case'*':
						a=a*b;
						printf("Result :%.2f\n",a);
						break;
						case'/':
						a=a/b;
						printf("Result :%.2f\n",a);
						break;
						case'%':
							a=(b*a)/100;
							printf("Result :%.2f\n",a);
							break;
							default:
								printf("Invalid Operator\n");
						
						}
	}
	while(sign!='q');
	printf("Thank you\n");
	getch();
}


Q How to print Diamond in c.
#include
#include
int main(void)
{
	int i,j,k,r,sp,p,no,n;
	printf("Enter any number :");
	scanf("%d",&no);
	n=no;
	for(r=1; r<=no; r++){
		for(sp=1; sp<=n; sp++){
			printf(" ");
		}
		n--;
		for(p=1; p<=r; p++){
			printf(" %d",r);
		}
		printf("\n");
	}
	for(i=no-1; i>=1; i--){
		for(j=i; j<=no; j++){
			printf(" ");
		}
		for(k=i; k>=1; k--){
			printf(" %d",i);
		}
		printf("\n");
	}
	getch();
}

Write a C program to enter two numbers and perform all arithmetic operations.

Write a C program to enter length and breadth of a rectangle and find its perimeter.
Write a C program to enter length and breadth of a rectangle and find its area.
Write a C program to enter radius of a circle and find its diameter, circumference and area.
Write a C program to enter length in centimeter and convert it into meter and kilometer.
Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
Write a C program to enter temperature in Fahrenheit and convert to Celsius
Write a C program to convert days into years, weeks and days.
Write a C program to find power of any number x ^ y.
Write a C program to enter any number and calculate its square root.
Write a C program to enter two angles of a triangle and find the third angle.
Write a C program to enter base and height of a triangle and find its area.
Write a C program to calculate area of an equilateral triangle.
Write a C program to enter marks of five subjects and calculate total, average and percentage.
Write a C program to enter P, T, R and calculate Simple Interest.
Write a C program to enter P, T, R and calculate Compound Interest.



#include
 #include
 #include
 int digitcube(int); // Function to separate digits, Cube them and add the cubes.
 int main() // main function
 {
 int number;
 printf("\n\tEnter a Positive Number? ");
 scanf("%d",&number);
 if (number <= 1)
 printf("The Number is One or Less than 1. Try again");
 else if(number==digitcube(number))
. printf("\n\tThe number %d is an Armstrong Number",number);
 else
printf("\n\tThe number %d is NOT an Armstrong Number",number);
.
 getch();
. return 0;
. } //main ends

 int digitcube(int num)

 {

 int sum=0, digit;
 while(num!=0)

 {
 digit=num%10; //separate a digit
 sum=sum+(int)pow(digit,3); //use power function to perform cube of digit
 //Note pow function uses float parameters and returns float
 num=num/10; //reduce the number
 }
 return sum;
 }

//Ascending Order
#include
#include
int main(void){
	int a[10],b,c,n,i,j;
	printf("Enter number of elements :");
	scanf("%d",&n);
	for(i=1; i<=n; i++){
		printf("Enter any number :");
		scanf("%d",&a[i]);
	}
	for(i=1; i<=n; i++){
		for(j=i+1; j<=n; j++){
			if(a[i]>a[j]){
			b=a[i];
			a[i]=a[j];
			a[j]=b;	
			}
		}
	}
	printf("Ascending Order :\n");
	for(i=1; i<=n; i++){
		printf("%d\t",a[i]);
	}
}


//Addition the elements of array
#include
#include
int main(void){
	int a[10],b,i,sum;
	printf("Enter number of elements to add :");
	scanf("%d",&b);
	sum=0;
	for(i=1; i<=b; i++){
		printf("Enter values :");
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	printf("Result :%d",sum);
	getch();
}


Comments

  1. IS THERE NO SOLN OF LAB FOR BCSL 13 , 21 , 22 , 32 , 33 , 34 , 43 , 44 , 45 , MCSL016 FROM 2014 TILL JUNE 2018

    ReplyDelete

Post a Comment

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

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: OUTPUT               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

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 *