Posts

Showing posts from July, 2019

Replace by Next Vowel

The program must accept a string  S  and an alphabet  CH  as the input. The program must replace all the occurrences of the alphabet  CH  by the next occurring vowel in the string S. Then the program must print the modified string as the output. Note:  If there is no vowel after the alphabet CH then CH must be printed as it is. Boundary Condition(s): 1 <= Length of the string <= 1000 Input Format: The first line contains the string S and an alphabet CH separated by a space. Output Format: The first line contains the modified string. Example Input/Output 1: Input: teleportation t Output: eeleporaaiion Example Input/Output 2: Input: accuracy c Output: auuuracy Solution:- #include<stdio.h> #include <stdlib.h> int vowel(char a) {     if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')     {         return 1;     }     return 0; } int main() {     char s[1000],a;     scanf("%s %c"

Sum of First K Integers

The program must accept  N  integers and an integer  K  as the input. The program must find the sum of the first K integers as S. The program must consider the last K integers and for each integer X among the last K integers, the program must print difference between S and X as the output. Boundary Condition(s): 1 <= N <= 10^5 1 <= K <= N Input Format: The first line contains the two integers N and K separated by a space. The second line contains N integers separated by spaces. Output Format: The first line contains K integers separated by space(s). Example Input/Output 1: Input: 7 5 10 20 30 40 50 60 70 Output: 120 110 100 90 80 Explanation: K = 5, The first 5 integers are 10, 20, 30, 40 and 50 and their sum is 150 (10 + 20 + 30 + 40 + 50). The last 5 integers are 30, 40, 50, 60 and 70. For integer 30, the difference between 150 and 30 is 120 (150-30). So  120  is printed. For integer 40, the difference between 150 and 40 is 110 (150-40). So  11

First X Characters for N times

The program must accept a string value  S  and two integers X and N as the input. The program must print the first X characters of S for N times as the output. Boundary Condition(s): 1 <= Length of S <= 100 1 <= X <= Length of S 1 <= N <= 100 Input Format: The first line contains the string S. The second line contains two integers X and N separated by a space. Output Format: The first line contains the first X characters of S for N times. Example Input/Output 1: Input: Rectangle 3 4 Output: RecRecRecRec Explanation: The word formed by the first 3 characters of  Rectangle  is  Rec . Then  Rec  is repeated for 4 times as  RecRecRecRec . Hence the output is  RecRecRecRec Example Input/Output 2: Input: january 7 2 Output: januaryjanuary solution:- #include<stdio.h> #include <stdlib.h> int main() {     char s[101];     int a,b;          scanf("%s\n%d %d",s,&a,&b);     char arr[a+1];          fo

Check Same Digit

The program must accept two integers  N1  and  N2  as the input. The program must print  Valid  if the tenth digit or the unit digit of N2 is present in N1. Else the program must print  Invalid  as the output. Boundary Condition(s): 10 <= N1, N2 <= 99 Input Format: The first line contains the two integer values N1 and N2 separated by a space. Output Format: The first line contains either Valid or Invalid. Example Input/Output 1: Input: 12 23 Output: Valid   Example Input/Output 2: Input: 90 13  Output: Invalid Solution:- #include<stdio.h> #include <stdlib.h> int main() {     int a,b;     scanf("%d %d",&a,&b);          if(b%10==a%10||b%10==(a/10)%10||(b/10)%10==a%10||(b/10)%10==(a/10)%10)     {         printf("Valid");     }     else     printf("Invalid"); }

Odd Digits Reverse Pattern

The program must accept an integer  N  as the input. The program must print the odd digits from the last digit and remove the last digit of N then again print the odd digits from the last digit and remove the last digit and so on. If there is no odd digit in the original N then print -1 as the output. Boundary Condition(s): 1 <= N <= 10^7 Input Format: The first line contains N. Output Format: The first line contains either odd digits as per the condition separated by a space or -1. Example Input/Output 1: Input: 12345 Output: 5 3 1 3 1 3 1 1 1 Explanation: In 12345, the odd digits  5 , 3  and  1  are printed. After removing the last digit the integer becomes  1234 . In 1234, the odd digits  3  and  1  are printed. After removing the last digit the integer is  123 . In 123, the odd digits  3  and  1  are printed. After removing the last digit the integer is  12 . In 12, the odd digit  1  is printed. After removing the last digit the integer becomes  1