Posts

Patch Up Two Matrices

Patch Up Two Matrices For this challenge, you need to take 2 matrices as an input from the stdin , add them and print the resultant matrix to the stdout. Input Format Two matrices to be taken as an input.  For each matrix, on first line you need to tell that how many rows and columns your matrix need to have and these values should be separated by space.  Then after that, each line will represent will represent each row and you need to enter numbers which each rows should have separated by a space.  Constraints 1 <  (n,m) < 100 1 <  (p,q) < 100 Output Format Print the resultant matrix to the stdout where each each line should represent Note  : Please do not include space after the numbers which are in the last column as it will affect your submission and you will not get marks. each row and values in the row should be separated by a space.  Sample TestCase 1 Input 3 3 1 2 3...

Write a recursive function to obtains the first 25 numbers of a Fibonacci sequence.

Q. Write a recursive function to obtains the first 25 numbers of a Fibonacci sequence .  Summary:- In Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, . . . 1. Without Recursion #include <stdio.h> int main() { int a=0,b=1,temp; int x =0; while(x<10) { printf(" %d ",b); temp=a+b; a=b; b=temp; x++; } return 0; } 2. By Recursion #include <stdio.h> int a=0,b=1,temp; int x =0; int main()       { if(x<10) { printf(" %d ",b); temp=a+b; a=b; b=temp; x++; main(); } return 0;        }

A positive integer is entered through the keyboard , write a program to obtain the prime factors of the number . Modify the function suitably to obtain the prime factors recursively .

Q. A positive integer is entered through the keyboard , write a program to obtain the prime factors of the number . Modify the function suitably to obtain the prime factors recursively . Summary:-  Here asking for prime factors. Prime numbers are those numbers who can be divided by only 1 and itself . Like:- 2,3,5,7...... . Algorithm: - 1.first take any positive input from the user.Let n . 2.make a code that could find prime number starting from 1 to the n . 3.if we get prime number from the above step , then check if n%pn==0 .pn = prime number. 4.If  n%pn==0  false ,then again go to  step 2 to find next prime number .  if   n%pn==0  is true , then print that number and make n=n/pn . Run this in loop till n%pn==0 is false. If this happens go to again at step 2 to find next prime number. 1. Without Recursion #include < stdio.h> void prime_fact (int ); int main () { int  n; printf ( " \n Enter a number: " ); ...

A 5-digit positive integer is entered through the keyboard ,write a recursive and non-recursive function sum of the 5-digit number.

A 5-digit positive integer is entered through the keyboard ,write a recursive and non-recursive function sum of the 5-digit number. 1. Non-Recursive copy:- #include <stdio.h> int main () { unsigned int n; int y =  0  ; printf ( " \n Enter the value: " ) ; scanf ( " %u " ,&n); while (n!= 0 ) { y = y +(n% 10 ); n = n/10; } printf ( " \n SUM = %d " ,y); return 0 ; } 2. Recursive #include <stdio.h> int  y; int   main () { unsigned   int  n; int  s; printf ( " \n Enter the value: " );   scanf ( " %u " ,&n); s = sum (n); printf ( " \n SUM =   %d " ,s); return   0 ; } int   sum ( unsigned   int  x) { if (x== 0 ) { return y; } else { y = (x% 10 ) + sum (x/ 10 )...

Write a function that receives marks received by a student in 3 subject and return the average and percentage of these marks. Call this function from main( ) and print the results in main( ).

Image
Write a function that receives marks received by a student in 3 subject and return the average and percentage of these marks. Call this function from main( ) and print the results in main( ). Summary of question:- * we have to make a function that can find the average and the percentage of the three values entered by the users. And then just have to print these output in main( ). Step 1: First we have to make the main( ) function , with all simple commands to take three values and to store in some variable or can simply use an array to store those three values. In this code we used array to store the values. (use float data type,as marks can be in decimal form) Then simply run a loop to take three value by the user and to store it in the array. Step 2: Now we have to make the function that can do all the stuffs we needed. The question is asking to return two values so we can use pointer to do so. function prototype Now just apply logic to make this ...

Write a function that receives 5 integers and returns the sum , average and standard deviation of these numbers. Call this function from main( ) and print the result in main( ).

Image
Q. Write a function that receives 5 integers and returns the sum , average and standard deviation of these numbers. Call this function from main( ) and print the result in main( ). In the question ,the marked words shows that we have to make a single user defined function instead of making three separate function  that can satisfy all the demands made by the given question.  NOTE: First we will ask user to input 5 integer values and will store all the values in an integer array.  Since we are using a single function fan( )   to return multiple values to main , so  we will use pointer to do so. In the function prototype , all parameters are pointers as : first parameter  is for accessing values of array. second , third and fourth parameters are for storing the addresses of the variables present in main( ) , which will be further initialized with the value of sum ,average and standard deviation respectively in the fan( ) . Since th...