Posts

C program to addition of two matrix.

Question: Write a C program to take elements of two matrix 3 X 3 and add both matrix. Source Code: #include int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i Output: Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Addition of two matrix is: 2 4 6 8 10 12 14 16 18

C program to swap elements of two Array.

Question: Write a C program to take two array of 5-5 elements and swap elements of Array A to Array B. Source Code: #include int main() { int arrA[5],arrB[5],i,temp; printf("Enter elements of Array A\n"); for(i=0;i Output: Enter elements of Array A 2 3 4 5 6 Enter elements of Array B 7 8 9 10 11 After Swapping arrayA arrayB 7 2 8 3 9 4 10 5 11 6

C program to find all even numbers from an Array.

Question: Write a C program to take 5 numbers from user and display all even numbers from them. Source Code: #include int main() { int arr[5],i; printf("Enter 5 numbers\n"); for(i=0;i Output: Enter 5 numbers 34 23 45 56 34 Even Numbers are: 34 56 34

C program to reverse the given number.|Without function | Using Function|

Question: Write a programm in C to reverse the given number. Source Code: #include int main() { int num,sum=0,rem; printf("Enter num \n"); scanf("%d",&num); while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); return 0; } Output: Enter num 345 Reverse of number: 543 Using Function: #include void reverse(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); reverse(num1); return 0; } Output: Enter num 789 Reverse of number: 987

C program to find sum of square of digit.|without function| with Function.

Question: Write a programm in C to find sum of square of digit of the number. Source Code: #include int main() { int num1,sum=0,rem; printf("Enter num1 \n"); scanf("%d",&num1); while(num1 !=0) { rem=num1%10; sum=sum+(rem*rem); num1=num1/10; } printf("Sum of square of digit: %d\n",sum); return 0; } Output: Enter num1 23 Sum of square of digit: 13 Using Function: #include void squareDigit(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=sum+(rem*rem); num=num/10; } printf("Sum of square of digit: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); squareDigit(num1); return 0; } Output: Enter num1 13 Sum of square of digit: 10

Write a C program to swapping of two numbers with and without third variable.

Source Code: without third variable. #include int main() { int num1,num2; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); num1=num1+num2; num2=num1-num2; num1=num1-num2; printf("Number after swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); return 0; } Output: Enter num1 67 Enter num2 45 Number before swapping: num1:67 num2:45 Number after swapping: num1:45 num2:67 With third variable: #include int main() { int num1,num2,num3; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); ...

Write C program to sort the given numbers in ascending orders.

Ascending order: Ascending order means the elements will be sorted in increasing order. Source Code: #include void main() { int num[5],i,j,temp; printf("Enter 5 numbers:\n"); for(i=0;i num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("soted elements are:\n"); for(i=0;i Output: Enter 5 numbers: 34 67 45 87 90 soted elements are: 34 45 67 87 90