Skip to main content

Posts

Showing posts with the label C Language

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},                             {

C Program to Check Armstrong Number

Before going to write the c program to check whether the number is Armstrong or not, let's understand what is Armstrong number. Armstrong number  is  a number that is equal to the sum of cubes of its digits . For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers. Let's try to understand why  153  is an Armstrong number. 153 = (1*1*1)+(5*5*5)+(3*3*3)   where:   (1*1*1)=1   (5*5*5)=125   (3*3*3)=27   So:   1+125+27=153   Example of second no  371 = (3*3*3)+(7*7*7)+(1*1*1)   where:   (3*3*3)=27   (7*7*7)=343   (1*1*1)=1   So:   27+343+1=371   This program computes all Armstrong numbers in the range of ! 0 and 999. An Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself. For example, 371 is an Armstrong number, since ! 3**3 + 7**3 + 1**3 = 371.  #include<stdio.h> #include<conio.h> int main(void){ int a,a2,a3,a4,b,b2,b3,c,i,j; printf("Enter any number :"); scanf("%d&quo

how to multiple number enter and sort the Ascending Order

how to multiple number enter and sort the Ascending Order #include<Stdio.h> #include<conio.h> 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]); } getch(); }

how to add n number of element of array

how to add n number  of element of array   how to  Addition the elements of array #include<stdio.h> #include<conio.h> 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(); }

make a calculator in c or write a code calculator

 #include<stdio.h> #include<conio.h> 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(

Write a program Ascending Order in c language

 //Ascending Order #include<Stdio.h> #include<conio.h> 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]); } }

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

write a C program to swap the values of two variables Using pointers

Question :- Using pointers, write a C program to swap the values of two variables. #include <stdio.h> #include<conio.h>   void main() {    int first_value, second_value, *first_pointer, *second_pointer, temp;      printf("Enter the value of First Value and Second Value\n");    scanf("%d%d", &first_value, &second_value);      printf("Before Swapping\nfirst_value = %d\nsecond_value = %d\n", first_value, second_value);      first_pointer = &first_value;    second_pointer = &second_value;      temp = *second_pointer;    *second_pointer = *first_pointer;    *first_pointer = temp;      printf("After Swapping\nfirst_value = %d\nsecond_value = %d\n", first_value, second_value);      getch(); } write a C program to swap the values of two variables Using pointers  int first_value, second_value, *first_pointer, *second_pointer, temp; it's declare variable two variable first_value and second_value it using to input a value by

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

Contact Form

Name

Email *

Message *