C program to perform arithmetic operations using switch case

#include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int ch; float a,b,res; clrscr(); printf(“Enter two numbers:”); scanf(“%f%f”,&a,&b); printf(“nMenun1.Additionn2.Subtractionn3.Multiplicationn4.Division”); printf(“nEnter your choice:”); scanf(“%d”,&ch); switch(ch) { case 1: res=a+b; break; case 2: res=a-b; break; case 3: res=a*b; break; case 4: res=a/b; break; default: printf(“Wrong choice!!nPress any key…”); getch(); exit(0); } printf(“nResult=%f”,res); getch(); }

C program to swap two numbers using pointers

#include<stdio.h> #include<conio.h> void main() { int *a,*b,*temp; clrscr(); printf(“Enter two mumbers:”); scanf(“%d%d”,a,b); printf(“Before Swaping:na=%d b=%d”,*a,*b); temp=a; a=b; b=temp; printf(“nAfter Swaping:na=%d b=%d”,*a,*b); getch(); }

C program to read and display an array using pointer

#include<stdio.h> #include<conio.h> void main() { int a[50],*p,i,n; clrscr(); p=a; printf(“Enter size of array:”); scanf(“%d”,&n); printf(“Enter elements of array:”); for(i=0;i<n;++i) scanf(“%d”,p+i); for(i=0;i<n;++i) printf(“%d “,*(p+i)); getch(); }

Matrix Addition in C

Here you will find program for matrix addition in C. Two matrix can be added only when number of rows and columns of first matrix is equal to number of rows of columns of second matrix. Matrix Addition in C #include<stdio.h> int main() { int a[5][5],b[5][5],c[5][5],i,j,m,n; printf(“How many rows and columns?”); scanf(“%d%d”,&m,&n); printf(“\nEnter first matrix:\n”); …

Matrix Addition in C Read More »