Posts

Functions - Null Matrix

QUESTION: Write a program to find whether the given matrix is null or not using functions. A null matrix is a matrix in which all its elements are zero. Function specification: int checkNull(int **a, int m, int n) The first argument corresponds to the pointer to an array. The second argument corresponds to the number of rows. The third argument corresponds to the number of columns. The function returns a value of 1 if it is a null matrix and 0 otherwise. Input and Output Format: Assume that the maximum number of rows and columns in the matrix is 10. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output 1: Enter the number of rows in the matrix 3 Enter the number of columns in the matrix 2 Enter the elements of the matrix 2 4 1 3 0 9 The matrix is 2 4 1 3 0 9 The matrix is not null Sample Input and Output 2: Enter th

Functions - Matrix Maximum

QUESTION: Write a program to find the maximum element in a matrix using functions. Function specification: int findMax(int **a, int m, int n) The first argument corresponds to the pointer to the matrix. The second argument corresponds to the number of rows in the matrix. The third argument corresponds to the number of columns in the matrix. Input and Output Format: Assume that the maximum number of rows and columns in the matrix is 10. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output : Enter the number of rows in the matrix 3 Enter the number of columns in the matrix 2 Enter the elements of the matrix 2 4 1 3 5 9 The matrix is 2 4 1 3 5 9 The maximum element in the matrix is 9 Function Definitions:   int findMax (int **a, int m, int n)  SOLUTION: #include<stdio.h> #include<stdlib.h> int fi

Bubble Sort

QUESTION: Write a C program to perform bubble sort on an array of n elements. Input Format: Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array. Output Format: Refer sample output for formatting specs. Sample Input and Output: [All text in bold corresponds to input and the rest corresponds to output] Enter the number of elements : 5 Enter element 1 34 Enter element 2 23 Enter element 3 67 Enter element 4 34 Enter element 5 2 Unsorted list is : 34 23 67 34 2 After Pass 1 elements are :23 34 34 2 67 After Pass 2 elements are :23 34 2 34 67 After Pass 3 elements are :23 2 34 34 67 After Pass 4 elements are :2 23 34 34 67 Sorted list is : 2 23 34 34 67 Note: stop the process if u find that the list is sorted in any intermediate point. SOLUTION: #include<stdio.h> int main() {     int n,i,j,temp,a[20]={0},k,flag;

Decipher my Ciphertext

QUESTION: Description: In the language of cryptography,  ciphertext  refers to a message encoded with a particular  key .  Plaintext  refers to the original, unencoded text. In this problem, both the ciphertext and the key are simply strings of upper-case characters. The ciphertext is generated from the plaintext by “adding” corresponding characters of the plaintext and the key together. If the plaintext is shorter than the key, only some of the key will be used. Similarly, if the plaintext is shorter than the key, the key will be used multiple times. For example, to encode the plaintext “HELLO” with the key “CAT”: Plaintext:  HELLO Key:  CATCA Ciphertext:  KFFOP And to encode the plaintext “DOG” with the key “FIDO”: Plaintext:  DOG Key:  FID Ciphertext:  JXK To add two letters together, use the following convention: A=1, B=2, …, Z=26. If the sum of two letters is greater than 26, subtract 26 from the sum. For example: A + E = 1 + 5 = 6 = F, and D + X =

Fibonacci Roots

QUESTION: The first two terms in the  Fibonacci sequence  are 0 and 1, respectively, and each subsequent term is the sum of the previous two. Using this definition to calculate the first several terms in the sequence, we get 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Let us define the  Fibonacci roots  of a positive integer  n  to be the two smallest consecutive Fibonacci numbers whose sum is greater than or equal to  n . Input Format: Input consists of a single integer which corresponds to n. Assumption: Assume that n is less than or equal to 2000. Output Format: Output consists of integers, separated by a space. Sample Input 1 : 31 Sample Output 1: 13 21 Sample Input 2 : 89 Sample Output 2: 34 55 SOLUTION: #include<stdio.h> int main() {     int a=0,b=1,c=0,n;     scanf("%d",&n);     while(1)     {         c=a+b;         if(c>=n)         goto END;         a=b;         b=c;     }     END: pr

Vowel or Consonant

QUESTION: Write a program to determine whether the input character is a vowel or consonant. Input and Output Format: Input consists of a single character. Output consists of a string --- “Vowel” / “Consonant” / “Not an alphabet” Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output 1: Enter a character a Vowel Sample Input and Output 2: Enter a character Z Consonant Sample Input and Output 3: Enter a character # Not an alphabet SOLUTION: #include<stdio.h> int main() {     char in;     char arr[11]={'a','e','i','o','u','A','E','I','O','U'};     int i,flag=0,con=0;     printf("Enter a character\n");     scanf("%c",&in);     if(((in>='a') && (in<='z')) || ((in>='A') &

Anagrams

QUESTION: Write a program to find whether the 2 given strings are anagrams or not. Anagrams  are words or phrases made by mixing up the letters of other words or phrases, Input and Output Format: Input consists of 2 string. Assume that all characters in the string are lowercase letters or spaces and the maximum length of the string is 100. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output 1: Enter the first string anitha Enter the second string amphisoft anitha and amphisoft are not anagrams Sample Input and Output 2: Enter the first string the eyes Enter the second string they see the eyes and they see are anagrams SOLUTION: #include<stdio.h> #include<string.h> int main() {     char s1[200],s2[200];     int first[26]={0},second[26]={0},c=0,i,flag=0;     printf("Enter the first string\n");