Example
INPUT:
5
OUTPUT:
3
Explanation:
hence maximum among three integer is 3.Hence 3 is printed as output.
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=Integer.toBinaryString(sc.nextInt()); int max=0; for(int i=0;i<str.length();i++){ StringBuilder s=new StringBuilder(str); s.deleteCharAt(i); int num=Integer.parseInt(s.toString(),2); if(num>max) max=num; } System.out.print(max); }}Print the desired pattern as shown below
Example
INPUT:
5233487
OUTPUT:
5433827
INPUT:
1002
OUTPUT:
1020
INPUT:
400352
OUTPUT:
2354
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); StringBuilder str=new StringBuilder(sc.next()); int len=str.length(),k=0,flag=1,index=0; char temp='0'; for(int i=0;i<len;i++) { if((str.charAt(i)-'0')%2==0&&flag==1) { temp=str.charAt(i); index=i; flag=0; } else if((str.charAt(i)-'0')%2==0&&flag==0) { char temp1=str.charAt(i); str.setCharAt(index,temp1); index=i; } } str.setCharAt(index,temp); System.out.print(Integer.parseInt(str.toString()));}}Print the desired pattern as shown below
Example
INPUT:
5 5
OUTPUT:
* * * * *
* 0 * 0 *
* * * * *
* 0 * 0 *
* * * * *
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); for(int i=0;i<x;i++) { for(int j=0;j<y;j++) { if(i%2==0||j%2==0) System.out.print("* "); else System.out.print("0 "); } System.out.println(); } }}if x is odd print main diagonal else print opposite diagonal.
Example
INPUT:
4
77 48 51 82
13 53 76 68
64 71 45 53
87 87 64 24
45
OUTPUT:
77 53 45 24
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int mat[n][n];int x;for(int i=0;i<n;i++){ for(int j=0;j<n;j++) { scanf("%d ",&mat[i][j]); }}scanf("%d",&x);int xrow,xcol;for(int row=0;row<n;row++){ for(int col=0;col<n;col++) { if(mat[row][col]==x) { xrow=row; xcol=col; break; } }}if(x%2==0){while(xrow>0&&xcol<n-1){ xrow--; xcol++;}printf("%d %d\n",xrow,xcol);while(xrow<n&&xcol>=0){ printf("%d ",mat[xrow][xcol]); xrow++; xcol--;}}else{ while(xrow>0&&xcol>0){ xrow--; xcol--;}printf("%d %d\n",xrow,xcol);while(xrow<n&&xcol<n){ printf("%d ",mat[xrow][xcol]); xrow++; xcol++;}}}#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int arr[n][n],flag=1;for(int row=0;row<n;row++){ for(int col=0;col<n;col++) { scanf("%d",&arr[row][col]); }}int temp=n-1;for(int row=0;row<n;row++){ for(int col=n/2;col<n;col++) { if(col<temp) printf("* "); else printf("%d ",arr[row][col]); } printf("\n"); if(row==n/2) { flag=0; } if(flag) temp--; else temp++;}}import java.util.Scanner;public class MyClass { static int count=0; static void fun(int num) { count+=Math.abs(num)/2; if(Math.abs(num)%2==1) count++; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(),y=sc.nextInt(); if(Math.abs(x-y)>=5) { count=Math.abs(x-y)/5; if(Math.abs(x-y)%5>0) fun(Math.abs(x-y)%5); } else if(Math.abs(x-y)>=2) { fun(Math.abs(x-y)); } else if(Math.abs(x-y)==1) count++; System.out.print(count); }}The program must accept an integer N as the input.The program must print the maximum possible sum S of integers which are having the same unit digit among the N integers.
Example Input/Output 1:
Input
5
60 69 39 98 20
Output
108
Explanation:
Maximum sum is 108 hence printed as the output.
Example input/Output 2:
Input:
8
15 98 67 95 18 93 48 97
Output:
164
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int max=0,arr[n],fre[10]={0};for(int i=0;i<n;i++){ scanf("%d",&arr[i]); fre[arr[i]%10]=1;}for(int i=0;i<10;i++){ int sum=0; if(fre[i]==1) { for(int j=0;j<n;j++) { if(i==arr[j]%10) sum+=arr[j]; } if(sum>max) max=sum; }}printf("%d",max);}The program must accept an integer N as the input.The program must toggle the last occurring 1 in the binary representation of N.The the program must print the modified value of N as the output.
Example Input/Output 1:
Input
10
Output
8
Explanation:
Example input/Output 2:
Input:
16
Output:
0
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); StringBuilder str=new StringBuilder(Integer.toBinaryString(sc.nextInt())); for(int i=str.length()-1;i>=0;i--) { if(str.charAt(i)=='1') { str.setCharAt(i,'0'); break; } } System.out.print(Integer.parseInt(str.toString(),2)); }}The program must accept an two integer as the input and print the number of common digits in it.
Example Input/Output 1:
Input
22
22222
Output
2
Example input/Output 2:
Input:
5465
47865
Output:
3
#include<stdio.h>#include <stdlib.h>int main(){int fre1[10]={0},fre2[10]={0};int a,b;scanf("%d%d",&a,&b);while(a!=0){ fre1[a%10]++; a/=10;}while(b!=0){ fre2[b%10]++; b/=10;}int count=0;for(int i=0;i<=9;i++){ if(fre1[i]<=fre2[i]&&fre1[i]!=0) count=count+fre1[i]; else if(fre1[i]>=fre2[i]&&fre1[i]!=0) count+=fre2[i];}printf("%d",count);}The program must accept an integer matrix of size RxC as the input.The program must print the number of rows containing the integers in ascending order in the matrix
Example Input/Output 1:
Input
4 5
4 6 7 8 19
1 3 5 7 8
3 5 6 12 6
5 7 8 9 13
Output
3
Example input/Output 2:
Input:
3 3
37 68 79
65 52 31
56 79 25
Output:
1
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int r,c,count=0; r=sc.nextInt(); c=sc.nextInt(); for(int row=0;row<r;row++) { int flag=0,temp=0; for(int col=0;col<c;col++) { int num=sc.nextInt(); if(col!=0&&temp>num) { flag=1; } else{ temp=num; } } if(flag==0) count++; } System.out.println(count); }}The program must accept N integers as the input and print the desired pattern as shown below
Example Input/Output 1:
Input
5
Output
%---%
---%-
--%--
-%---
%---%
Example input/Output 2:
Input:
7
Output:
%-----%
-----%-
----%--
---%---
--%----
-%-----
%-----%
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);for(int i=0;i<n;i++){ for(int j=0;j<n;j++) { if(i==0||i==n-1) printf((j==0||j==n-1)?"%%":"-"); else printf((j==n-1-i)?"%%":"-"); } printf("\n");}}The program must accept N integers as the input.The program must remove the first occurrence of 0 in each integer among the N integers.Then the program must print the sum of the N modified integers as the output.
Example Input/Output 1:
Input
3
100 320 10020
Output
1062
Explanation:
Example input/Output 2:
Input:
4
87 157 10 13
Output:
258
#include<stdio.h>#include <stdlib.h>int main(){int n,sum=0;scanf("%d",&n);for(int i=0;i<n;i++){ char str[100],tempstr[100]; scanf("%s",str); int ctr=1,index=0; for(int j=0;j<strlen(str);j++) { if(str[j]=='0'&&ctr) { ctr--; } else { tempstr[index++]=str[j]; } } tempstr[index]='\0'; sum=sum+atoi(tempstr); }printf("%d",sum);}The program must accept a N*N matrix as the input The program must modify the matrix based on the following conditions in the given order.
-The top-right quadrant of the matrix is replaced by the bottom-left quadrant.
-The bottom-right quadrant of the matrix is replaced by the top-left quadrant.
Finally the program must print the modified matrix as the output.
Example Input/Output 1:
Input
4
25 28 84 71
15 30 45 87
69 78 99 10
11 54 68 100
Output
25 28 69 78
15 30 11 54
69 78 25 28
11 54 15 30
Example input/Output 2:
Input:
6
25 28 84 71 88 77
15 30 45 87 22 33
69 78 99 10 27 18
11 54 68 100 19 08
69 78 99 10 27 18
10 20 30 40 50 60
Output:
25 28 84 11 54 68
15 30 45 69 78 99
69 78 99 10 20 30
11 54 68 25 28 84
69 78 99 15 30 45
10 20 30 69 78 99
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int mat[n][n];for(int row=0;row<n;row++){ for(int col=0;col<n;col++) { scanf("%d",&mat[row][col]); }}int a=0;for(int row=n/2;row<n;row++){ int b=0; for(int col=n/2;col<n;col++) { mat[row][col]=mat[a][b]; b++; } a++;}for(int row=0;row<n/2;row++){ int b=0; for(int col=n/2;col<n;col++) { mat[row][col]=mat[a][b]; b++; } a++;}for(int row=0;row<n;row++){ for(int col=0;col<n;col++) printf("%d ",mat[row][col]); printf("\n");}}The program must accept a character matrix of size RxC containing only lower case alphabets as the input.The program must print the first occurring vowel from the top in each column of the matrix.
Note:
Example Input/Output 1:
Input
524 1200
Output
1724
Explanation:
Example input/Output 2:
Input:
1000 2000
Output:
3000
#include<stdio.h>#include <stdlib.h>#include<string.h>int main(){char num1[100],num2[100];scanf("%s %s",num1,num2);for(int i=strlen(num2)-1;i>=0;i--){ if(num2[i]!='0') { char temp=num1[0]; num1[0]=num2[i]; num2[i]=temp; break; }}printf("%d",atoi(num1)+atoi(num2));}The program must accept two integers X and Y as the input.The program must swap the first digit of X and the last occurring nonzero digit of Y.Then the program must print the sum of X and Y as the output.
Example Input/Output 1:
Input
524 1200
Output
1724
Explanation:
Example input/Output 2:
Input:
1000 2000
Output:
3000
#include<stdio.h>#include <stdlib.h>#include<string.h>int main(){char num1[100],num2[100];scanf("%s %s",num1,num2);for(int i=strlen(num2)-1;i>=0;i--){ if(num2[i]!='0') { char temp=num1[0]; num1[0]=num2[i]; num2[i]=temp; break; }}printf("%d",atoi(num1)+atoi(num2));}Print the desired pattern shown in he example
Example Input/Output 1:
Input
3
1 2 3
4 5 6
7 8 9
Output
1
2 4
3 5 7
6 8
9
Example input/Output 2:
Input:
5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Output:
1
2 6
3 7 11
4 8 12 16
5 9 13 17 21
10 14 18 22
15 19 23
20 24
25
#include<stdio.h>int main() { int n; scanf("%d",&n); int mat[n][n]; for(int row=0;row<n;row++) { for(int col=0;col<n;col++) scanf("%d",&mat[row][col]); } int ctr=0; while(1) { for(int row=0;row<n;row++) { for(int col=0;col<n;col++) { if(row+col==ctr) printf("%d ",mat[row][col]); } } printf("\n"); ctr++; if(ctr==n+n-1) break; }}Mr.ABC has M boxes and N keys.Each box contains a certain number of gold coins and each key has a number written on it.The number of gold coins in ecah box and the number written on each key are passed as the input to the program.He wants to open as many boxes as possible based on the following conditions.
The program must print the maximum number of boxes he can open based on the given conditions.
Example Input/Output 1:
Input
4 3
8 2 1 7
2 9 5
Output
3
Explanation:
Example input/Output 2:
Input:
3 4
10 8 1
20 30 40 50
Output:
1
#include<stdio.h>#include <stdlib.h>int main(){int b,k;scanf("%d %d",&b,&k);int box[b],key[k];for(int i=0;i<b;i++)scanf("%d",&box[i]);for(int i=0;i<k;i++)scanf("%d",&key[i]);int count=0;for(int i=0;i<k;i++){ for(int j=0;j<b;j++) { if((box[j]%2==0&&box[j]!=-1)&&key[i]%2==1) { count++; box[j]=-1; break; } else if((box[j]%2==1&&box[j]!=-1)&&key[i]%2==0) { count++; box[j]=-1; break; } }}printf("%d",count);}The program must accept an string as input and print the desired pattern as the output as shown in example section.
Example Input/Output 1:
Input
12345
Output
**1**
*2*2*
34543
Example input/Output 2:
Input:
skillrack
Output:
****s****
***k*k***
**i***i**
*l*****l*
lrackcarl
Example input/Output 3:
Input:
abcdefg
Output:
***a***
**b*b**
*c***c*
defgfed
#include<stdio.h>#include <stdlib.h>int main(){char str[100];int len;scanf("%s%n",str,&len);int ctr=len/2,flag=1;for(int i=0;i<len;i++){ int index=i; if(ctr-i==-1) break; for(int j=0;j<len;j++) { if(ctr-i==0) { printf("%c",(flag)?str[index++]:str[index--]); if(index==len-1) flag=0; } else printf("%c",(j==ctr-i||j==ctr+i)?str[i]:'*'); } printf("\n");}}The program must accept a two lines of N integers each as the input.The program must print the odd integers from both the lines based on their order of occurrence as the output.if both lines having odd integers in the same position then print the odd integer from the first line followed by the odd integer from the second line
Example Input/Output 1:
Input
5
11 10 12 13 77
45 44 44 43 10
Output
11 45 13 43 77
Example input/Output 2:
Input:
4
3 1 4 8
6 2 7 9
Output:
3 1 7 9
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr1[]=new int[n],arr2[]=new int[n]; for(int i=0;i<n;i++) arr1[i]=sc.nextInt(); for(int i=0;i<n;i++) arr2[i]=sc.nextInt(); for(int i=0;i<n;i++) { if(arr1[i]%2==1) System.out.print(arr1[i]+" "); if(arr2[i]%2==1) System.out.print(arr2[i]+" "); } }}The program must accept a integer N as the input and print YES if all the digits in the integer are in ascending order else print NO.
Example Input/Output 1:
Input
25689
Output
YES
Example input/Output 2:
Input:
54789
Output:
NO
#include<stdio.h>int main() { int R,C,count=0; scanf("%d %d\n",&R,&C); for(int row=0;row<R;row++) { int flag=0; char ch; for(int col=0;col<C;col++) { char str[2]; scanf("%s",str); if(col==0) { ch=str[0]; continue; } else if(str[0]<ch) { flag=1; } ch=str[0]; } if(!flag) count++; } printf("%d",count);}The program must accept a integer N as the input and print YES if all the digits in the integer are in ascending order else print NO.
Example Input/Output 1:
Input
25689
Output
YES
Example input/Output 2:
Input:
54789
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){int arr[8],index=0,flag=0;while(scanf("%1d",&arr[index])>0){ if(index!=0) { if(arr[index]<arr[index-1]) flag=1; } index++;}printf(flag?"NO":"YES");}The program must accept a string S as the input.The program must print the desired pattern as shown in the Example Input/Output section
Example Input/Output 1:
Input
skillrack
Output
s********
ks*******
ski******
liks*****
skill****
rlliks***
skillra**
carlliks*
skillrack
Example input/Output 2:
Input:
malayalam
Output:
m********
am*******
mal******
alam*****
malay****
ayalam***
malayal**
alayalam*
malayalam
#include<stdio.h>#include <stdlib.h>int main(){char str[101];int len;scanf("%s%n",str,&len);for(int i=0;i<len;i++){ for(int j=0;j<len;j++) { if(j<=i) printf("%c",(i%2==0)?str[j]:str[i-j]); else printf("*"); } printf("\n");}}A boy has M 1 rupee coins and N X rupee coins.He needs to pay a bill of K rupees .The values of X,M,N and K are passed as input to the program.The program must print YES if it is possible to pay exactly K rupees from the M 1 rupee coins and the N X rupee coins.Else the program must print NO as the output.
Example Input/Output 1:
Input
2 6 5 13
Output
YES
Explanation :
There are six 1 rupee coins and five 2 rupee coins.From that the sum of five 2 rupee coins (5*2=10) and three 1 rupee coins (3*1=3) is 13.So YES is printed as output.
Example input/Output 2:
Input:
3 1 8 14
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){int X,M,N,K;scanf("%d %d %d %d",&X,&M,&N,&K);int check=K%N;if(((X*N)+M)<K){ printf("NO"); return 0;}printf(M>=check?"YES":"NO");}The program must accept a string S containing only lower case alphabets and an integer Kas the input. The program must print YES if the first K English alphabets (lower case) are present at least once in the string S. Else the program must print NO as the output.
Example Input/Output 1:
Input
afehijklmnopzqrcstuvdwxgyb
5
Output
YES
Explanation :
The first 5 english alphabets (lower case) are a b c d and e which are present at least once in the string afehijklmnopzqrcstuvdwxgyb
So YES is printed.
Example input/Output 2:
Input:
bdhajrgst
3
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){char str[101];int len,x,fre[26]={0},flag=1;scanf("%s%n%d",str,&len,&x);for(int i=0;i<len;i++)fre[str[i]-'a']=1;for(int i=0;i<x;i++){ if(fre[i]!=1) flag=0;}printf(flag==1?"YES":"NO");}The program must accept an number of integer as an input and print the desired pattern as shown in example section.
Example Input/Output 1:
Input:
7 3 4 5
Output:
****
****
****
*-**
*--*
*---
*---
Example Input/Output 2:
Input:
5 6 1 4 2
Output:
*****
**-**
**-*-
**-*-
**---
-*---
Example Input/Output 3:
Input:
1 2 3 4 5 6
Output:
******
-*****
--****
---***
----**
-----*
#include<stdio.h>int main() { int index=0,max=0; int arr[100]; while(scanf("%d",&arr[index])>0) { if(arr[index]>max) max=arr[index]; index++; } char pattern[index]; for(int i=0;i<max;i++) { for(int j=0;j<index;j++) { if(i==arr[j]) pattern[j]='-'; else if(pattern[j]!='-') pattern[j]='*'; } pattern[index]='\0'; printf("%s\n",pattern); }}The program must accept a string S with space as the input.The program convert the alphabets to uppercase in between the square brackets [] .And finally print the modified string as the output.
Example Input/Output 1:
Input:
[as[df]er]
Output:
[as[DF]er]
Example Input/Output 2:
Input:
[robert [was] a good [king]
Output:
[robert [WAS] a good [KING]
Example Input/Output 3:
Input:
uhuu [ntu e]tuhnt[uheo
Output:
uhuu [NTU E]tuhnt[uheo
#include<stdio.h>#include<string.h>int main() { char str[1001]; int len; scanf("%[^\n]%n",str,&len); int i=0; while(i<len) { int flag=0,j=i+1; if(str[i]=='[') { while(j<len) { if(str[j]==']') { flag=1; break; } else if(str[j]=='[') { flag=0; break; } j++; } } if(flag==1) { for(int index=i+1;index<j;index++) str[index]=toupper(str[index]); i=j; } else { i++; } } for(int a=0;a<len;a++) printf("%c",str[a]);}The program must accept a string S as the input.The program must print the desired pattern as shown in the example Input/Output section.
Example Input/Output 1:
Input:
water
Output:
w * * * a
* t * e *
* * r * *
* t * e *
w * * * a
Example Input/Output 2:
Input:
OFFICE
Output:
O * * * * F
* F * * I *
* * C E * *
* * C E * *
* F * * I *
O * * * * F
#include<stdio.h>#include <stdlib.h>int main(){char str[100];int len,ctr=0;scanf("%s%n",str,&len);char arr[len][len];int end=(len%2)?(len/2)+1:len/2;for(int row=0;row<end;row++){ for(int col=0;col<len;col++) { if(col==row||col==len-row-1) { arr[row][col]=str[ctr]; ctr++; } else arr[row][col]='*'; }}for(int row=0;row<end;row++){ for(int col=0;col<len;col++) printf("%c ",arr[row][col]); printf("\n");}int end1=(len%2)?end-2:end-1;for(int row=end1;row>=0;row--){ for(int col=0;col<len;col++) printf("%c ",arr[row][col]); printf("\n");}}The program must accept a string S as the input.The program must print the desired pattern as shown in the example Input/Output section.
Example Input/Output 1:
Input:
skillrack
Output:
skillrack
kkillrack
iiillrack
lllllrack
lllllrack
rrrrrrack
aaaaaaack
cccccccck
kkkkkkkkk
Example Input/Output 2:
Input:
huge
Output:
huge
uuge
ggge
eeee
#include<stdio.h>#include <stdlib.h>int main(){char str[101];scanf("%s",str);int n=strlen(str);for(int i=0;i<n;i++){ int count=i; while(count--) printf("%c",str[i]); printf("%s",&str[i]); printf("\n");}}The program must accept an N integers as the input the program must swap the first occurred odd integers and second odd integer and so on and print the modified integers as the output.If the last integer is odd it should not be swapped.
Example Input/Output 1:
Input:
7
22 23 51 56 69 53 29
Output:
22 51 23 56 53 69 29
Example Input/Output 2:
Input:
7
22 24 51 56 68 52 29
Output:
22 24 51 56 68 52 29
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int arr[n],first=-1,ctr=1;for(int i=0;i<n;i++){ scanf("%d ",&arr[i]); if(ctr&&arr[i]%2) { first=i; ctr=0; } else if(i==n-1) { continue; } else if(arr[i]%2&&first!=-1) { int temp=arr[first]; arr[first]=arr[i]; arr[i]=temp; first=-1; ctr=1; }}for(int i=0;i<n;i++)printf("%d ",arr[i]);}The program must accept a string S as the input and pint the sub string from last to first.
Example Input/Output 1:
Input:
Brick
Output:
kckickrickBrick
Example Input/Output 2:
Input:
SkillRack
Output:
kckackRacklRackllRackillRackkillRackSkillRack
#include<stdio.h>#include <stdlib.h>int main(){char str[101];scanf("%s",str);int len=strlen(str);for(int i=0;i<len;i++){ for(int j=len-i-1;j<len;j++) { printf("%c",str[j]); }}}The program must accept N integers as the input.The program must form a binary representation B by concatenating the last two bits of each integer among the N integers(left to right).Then the program must print the decimal equivalent of B as the output.
Example Input/Output 1:
Input:
4
7 5 8 2
Output:
210
Explanation:
Example Input/Output 2:
Input:
3
12 10 32
Output:
8
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int bin[1000],index=0;for(int i=0;i<n;i++){ int num; scanf("%d ",&num); int ctr=0; while(ctr<2) { bin[index]=num%2; num/=2; index++; ctr++; } int temp=bin[index-1]; bin[index-1]=bin[index-2]; bin[index-2]=temp;}long long sum=0,count=0;for(int i=index-1;i>=0;i--){ if(bin[i]==1) { sum+=(long long)pow(2,count); } count++;}printf("%lld",sum);}The program must accept accept the string S containing only lower case alphabets as the input.The program must print Yes if all the consonants are present in the string S(in any order).Else the program must print No as the output.
Example Input/Output 1:
Input:
abcdefghijklmnopqrstuvwxyz
Output:
YES
Example Input/Output 2:
Input:
pqbchjrtvwmdgefdiugi
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){char str[101];scanf("%s",str);int fre[26]={0};for(int i=0;i<strlen(str);i++){ if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u') fre[str[i]-'a']=1;}int count=0;for(int i=0;i<26;i++){ if(fre[i]==1) count++;}printf(count==21?"YES":"NO");}The program must accept N integers as the input.The program must print the values from 1 to N where the sum of odd digits is equal to the sum of even digits as the output
Example Input/Output 1:
Input:
160
Output:
112 121 134 143 156
Example Input/Output 2:
Input:
500
Output:
112 121 134 143 156 165 178 187 211 314 336 341 358 363 385 413 431
#include<stdio.h>#include <stdlib.h>int main(){int N;scanf("%d",&N);for(int i=112;i<=N;i++){ int oddsum=0,evensum=0,num=i; while(num!=0) { if((num%10)%2==1) oddsum+=(num%10); else evensum+=(num%10); num/=10; } if(oddsum==evensum) printf("%d ",i);}}The program must accept N integers as the input.The program must print the smallest possible integer by removing exactly one digit from the last three digit.
Example Input/Output 1:
Input:
7654
Output:
754
Example Input/Output 2:
Input:
987987
Output:
98787
Example Input/Output 3:
Input:
100
Output:
0
#include<stdio.h>#include <stdlib.h>#include<string.h>#include<math.h>int main(){char str[1001];scanf("%s",str);int maxindex,i;char max='0';i=strlen(str)-3;for(;i<strlen(str);i++){ if(str[i]>max) { maxindex=i; max=str[i]; }}long long int num=0;int len=pow(10,strlen(str)-2);for(int j=0;j<strlen(str);j++){ if(j!=maxindex) { num=num+(str[j]-'0')*len; len/=10; }}printf("%lld",num);}The program must accept N integers as the input.The program must print the sum of the largest digit in each integer among the N integerrs as the output.
Example Input/Output 1:
Input:
5
87 1654 121 657 15
Output:
28
Explanation:
Example Input/Output 2:
Input:
4
0 444 10 25
Output:
10
#include<stdio.h>#include <stdlib.h>int main(){int n,num,sum=0;scanf("%d",&n);for(int i=0;i<n;i++){ int max=0; scanf("%d",&num); while(num!=0) { if(num%10>max) max=num%10; num/=10; } sum+=max;}printf("%d",sum);}The program must accept a string S (encrypted string) containing only .(Dots) and-(Hyphens) as the input.The encryption algorithm is given below.
The program must decrypt the string s and print it as the output.
Example Input/Output 1:
Input:
.-.--
Output:
012
Example Input/Output 2:
Input:
--.
Output:
20
#include<stdio.h>#include <stdlib.h>int main(){char str[1001];scanf("%s",str);int i=0;while(i<=strlen(str)-1){ if(str[i]=='.') { printf("0"); i++; } else if(str[i]=='-'&&str[i+1]=='.') { printf("1"); i+=2; } else if(str[i]=='-'&&str[i+1]=='-') { printf("2"); i+=2; }}}The program must accept an integer N as the input.The program generate a sequence of integers from 1 to N.Then the program must replace each integer X in the sequence based on the following conditions:
Example Input/Output 1:
Input:
15
Output:
1
2
Skill
4
Rack
Skill
7
8
Skill
Rack
11
Skill
13
14
SkillRack
Example Input/Output 2:
Input:
5
Output:
1
2
Skill
4
Rack
#include<stdio.h>int main() { int x; scanf("%d",&x); for(int i=1;i<=x;i++) { if(i%3==0&&i%5==0) printf("SkillRack\n"); else if(i%3==0) printf("Skill\n"); else if(i%5==0) printf("Rack\n"); else printf("%d\n",i); }}The program must accept a string S with spaces as the input.For each word W in the string S,the program must replace the last character of W by the first character of the next word.For the last word the program must replace the last character by the first word.Finally the program must print the modified string S as the output.
Example Input/Output 1:
Input:
Nice to meet you
Output:
Nict tm meey yoN
Example Input/Output 2:
Input:
k g s n i g j n
Output:
g s n i g j n k
4Example Input/Output 3:
Input:
tit for tat
Output:
tif fot tat
#include<stdio.h>#include <stdlib.h>int main(){char str[1000];scanf("%[^\n]",str);char temp=str[0];for(int i=0;i<strlen(str);i++){ if(str[i]==' ') str[i-1]=str[i+1];}str[strlen(str)-1]=temp;printf("%s",str);}The program must accept an integer N as the input.The program must print the desired pattern as shown in the example
Example Input/Output 1:
Input:
9165
Output:
9165
165
65
5
Example Input/Output 2:
Input:
108004
Output:
108004
8004
8004
4
4
4Example Input/Output 3:
Input:
8525849176
Output:
8525849176
525849176
25849176
5849176
849176
49176
9176
176
76
6
#include<stdio.h>#include <stdlib.h>int main(){long int num;int len;scanf("%ld%n",&num,&len);long int divi=pow(10,len);while(divi!=1){ printf("%ld\n",num%divi); divi/=10;}}The program must accept two string as the input,the program must print sub string which is having the maximum length and occurring at the seams position in both the string values.if both sub string has same length print the first occurred one.(two string has same length)
Example Input/Output 1:
Input:
skillrack
SkillRack
Output:
kill
Explanation:
skillrack,SkillRack.since kill has maximum length kill is printed.
Example Input/Output 2:
Input:
abcxxyzmn
abdxyzkmn
Output:
ab
#include<stdio.h>#include <stdlib.h>#include<string.h>int main(){char str1[1000],str2[1000];scanf("%s %s",str1,str2);int i=0,j=0,start,end,max,ctr=0,maxstart,maxend,count=0;while(i<strlen(str1)){ if(str1[i]==str2[j]) { if(ctr==0) { start=i; } end=i; ctr=1; count++; } if(count>max) { max=count; maxstart=start; maxend=end; } if(str1[i]!=str2[j]) { ctr=0; count=0; } i++; j++;}for(int i=maxstart;i<=maxend;i++) printf("%c",str1[i]);}The program must accept N integers as the input.The program must print he sum of integers containing at least two odd digits among the N integers as the output.
Example Input/Output 1:
Input:
5
78 549 123 877 214
Output:
1549
Explanation:
Example Input/Output 2:
Input:
4
124 4266 184 42
Output:
0
#include<stdio.h>#include <stdlib.h>int main(){int n,sum=0;scanf("%d",&n);int num;for(int i=0;i<n;i++){ scanf("%d ",&num); int a=num,count=0; while(a!=0) { if(a%2==1) count++; a=a/10; } if(count>=2) sum=sum+num;}printf("%d",sum);}The program must accept a string S containing only lower case alphabets as the input.For each sub string containing only vowels in the string S,the program must encloses the sub string by a pair of curly braces.Then the program must print the modified string S as the output.
Example Input/Output 1:
Input:
bookreadin
Output:
b{oo}kr{ea}d{i}ng
Example Input/Output 2:
Input:
aeiou
Output:
{aeiou}
Example Input/Output 3:
Input:
apple
Output:
{a}ppl{e}
#include<stdio.h>#include <stdlib.h>#include<string.h>int isvowel(char ch){ if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') return 1; else return 0;}int main(){char str[101];int ctr=0;scanf("%s",str);for(int i=0;i<strlen(str);i++){ if(isvowel(str[i])&&ctr==0) { printf("{"); ctr=1; } else if(ctr==1&&!isvowel(str[i])) { printf("}"); ctr=0; } printf("%c",str[i]); if((i==strlen(str)-1)&&isvowel(str[i])) printf("}"); }}The program must accept a fraction X/Y as the input.X represents the size of the pattern and Y represents the number of digits required to represent each integer in the pattern.The program must print the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
5/3
Output:
001 002 003 004 005
006 007 008 009 010
011 012 013 014 015
016 017 018 019 020
021 022 023 024 025
Example Input/Output 2:
Input:
3/5
Output:
00001 00002 00003
00004 00005 00006
00007 00008 00009
Example Input/Output 3:
Input:
10/
Output:
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
#include<stdio.h>#include <stdlib.h>int main(){int n,len,k=1;scanf("%d/%d",&n,&len);for(int i=0;i<n;i++){ for(int j=0;j<n;j++) { if(len==1&&k==10) { k=0; } printf("%0*d ",len,k); k++; } printf("\n");}}The program must accept a string S as the input.The program must find and print the number of occurrences of last two characters of S in the same string S as the output.
Example Input/Output:
Input:
hiabchi
Output:
2
Explanation:
The last two characters of the string hiabchi are h and i.Here the hi has occurred 2 times in the string hiabchi.
Hence the output is 2.
Example Input/Output:
Input:
MOOONOO
Output:
3
#include<stdio.h>#include <stdlib.h>int main(){char str[10000];int len,count=0;scanf("%s%n",str,&len);char first=str[len-2],sec=str[len-1];for(int i=0;i<len-1;i++){ if(str[i]==first&&str[i+1]==sec) count++;}printf("%d",count);}The program must accept an integer N as the input.The program must remove the tenth digit of all the N integers.Then the program must print the sum of N modified integers as the output.
Example Input/Output:
Input:
4
180 212 5295 5001
Output:
1058
Explanation:
After removing tenth digit the integer becomes 10 22 525 501 and their sum is 1058.Hence 1058 is printed as output.
Example Input/Output:
Input:
5
212 481 548 6545 1
Output:
777
#include<stdio.h>#include <stdlib.h>int main(){int n,num,sum=0;scanf("%d",&n);for(int i=0;i<n;i++){ scanf("%d ",&num); sum=sum+((num%10)+(num/100)*10);}printf("%d",sum);}The program must accept an integer N as the input.The program must convert the decimal value to its equivalent binary values and print the binary value in desired pattern as shown below.
Example Input/Output:
Input:
463
Output:
111
00
1111
Explanation:
The binary value of 463 is 111001111.
Example Input/Output:
Input:
81
Output:
1
0
1
000
1
#include<stdio.h>#include <stdlib.h>long int b,k=0;void binary(int n){ if(n!=0) { binary(n/2); int a=n%2; if(k==0) { b=a; k=1; } if(b!=a) printf("\n"); printf("%d",a); b=a; }}int main(){long long int N;scanf("%lld",&N);binary(N);}#include<stdio.h>#include <stdlib.h>int main(){long long int N;scanf("%lld",&N);long int arr[1001],i=0;while(N>0){ arr[i++]=N%2; N=N/2;}for(int j=i-1;j>=0;j--){ printf("%ld",arr[j]); if(arr[j]!=arr[j-1]) printf("\n"); }}The program must accept an integer N as the input.The program must remove the last occurring consecutive odd digits of N if the last digit of N is odd.Else the program must remove the last occurring consecutive even digits of N.Finally the program must print the modified integer as the output.
Example Input/Output:
Input:
2315642
Output:
2315
Example Input/Output:
Input:
92423
Output:
9242
#include<stdio.h>#include <stdlib.h>int main(){char str[10001];int len,ctr;scanf("%s%n",str,&len);if((str[len-1]-'0')%2==0) ctr=0;else ctr=1;for(int i=len-1;i>=0;i--){ int digit=str[i]-'0'; if(digit%2!=ctr) { str[i+1]=NULL; break; }}printf("%s",str);}The program must accept an odd integer N as the input.The program must print the desired pattern as shown in the Example.
Example Input/Output:
Input:
5
Output:
1 * 1
2 2 *
3 * *
4 4 *
5 * 5
Example Input/Output:
Input:
7
Output:
1 * * 1
2 * 2 *
3 3 * *
4 * * *
5 5 * *
6 * 6 *
7 * * 7
#include<stdio.h>#include <stdlib.h>int main(){int N;scanf("%d",&N);int ctr=(N/2)+1;for(int i=1;i<=N;i++){ for(int j=1;j<=(N/2)+1;j++) { if(j==1||j==ctr) printf("%d ",i); else printf("* "); } printf("\n"); if(i>=(N/2)+1) ctr++; else ctr--; }}The program must accept a integer N which contains 1's and 0's .The program is to find the decimal value by rearranging the 1's first and 0's followed by it.
Example Input/Output:
Input:
4
1 0 0 1
Output:
12
Explanation:
It is rearranged as 1100 and the decimal value of 1100 is 12 which is printed as output.
Example Input/Output:
Input:
42
1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1
Output:
4398046248960
#include<stdio.h>#include <stdlib.h>int main(){int N;scanf("%d",&N);int a,count1=0,count0=0;for(int i=0;i<N;i++){ scanf("%d",&a); if(a==1) count1++; else count0++;}long long int sum=0;for(int i=0;i<count1;i++){ sum=sum+((long int)1<<count0); count0++;}printf("%lld",sum);}The program must accept a string s where the length of s is always a multiple of 4 as the input.The program must split the string S into four equal parts.Then the program must reverse the characters in each part.Then the program must print the modified four parts of string
Example Input/Output:
Input:
paraacetoaminophenol
Output:
aarap aotec ponim loneh
Example Input/Output:
Input:
FAST
Output:
F A S T
#include<stdio.h>#include <stdlib.h>char str[1001];void print(int from,int to){ while(from>=to) { printf("%c",str[from--]); } printf(" ");}int main(){int len;scanf("%s%n",str,&len);int start=0,end=(len/4)-1;for(int i=0;i<4;i++){ print(end,start); start+=len/4; end+=len/4;}}Example Input/Output:
Input:
National
Output:
Natainol
Explanation:
National contains a,i,o,a as vowels after rotating the vowels in clockwise direction for 1 time the string become Natainol. Hence it is printed as output
Example Input/Output:
Input:
AEiou
Output:
uAEio
#include<stdio.h>#include <stdlib.h>int isvowel(char ch){ ch=tolower(ch); if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') return 0; return 1;}void main(){char str[1001],vowel[1001];int len,index=0;scanf("%s%n",str,&len);for(int i=0;i<len;i++){ if(!isvowel(str[i])) vowel[index++]=str[i];}char temp=vowel[index-1];for(int i=index-1;i>0;i--){ vowel[i]=vowel[i-1];}vowel[0]=temp;int ctr=0;for(int i=0;i<len;i++){ if(!isvowel(str[i])) str[i]=vowel[ctr++];}printf("%s",str);}Example Input/Output:
Input:
5
1 1 2 3 1
Output:
YES
Explanation:
The sequence 1 2 3 is occurred in the 5 integers. Hence,the output will be YES
Example Input/Output:
Input:
6
1 2 1 2 13
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int arr[n],count=0;for(int i=0;i<n;i++){ scanf("%d ",&arr[i]); if(arr[i]==3&&arr[i-1]==2&&arr[i-2]==1) count=1;}if(count) printf("YES");else printf("NO");}Example Input/Output:
Input:
5
Output:
1 5 2 4 3 3 4 2 5 1
* 1 4 2 3 3 2 4 1 *
* * 1 3 2 2 3 1 * *
* * * 1 2 2 1 * * *
* * * * 1 1 * * * *
Example Input/Output:
Input:
3
Output:
1 3 2 2 3 1
* 1 2 2 1 *
* * 1 1 * *
#include<stdio.h>int main() { int num,count=0; scanf("%d",&num); int a=1,b=num; for(int i=0;i<num;i++) { for(int j=0;j<num*2;j++) { if(j<i||j>=(num*2)-i) printf("* "); else { if(j>=i) { if(count==0) { printf("%d ",a); a++; count=1; } else { printf("%d ",b); b--; count=0; } } } } printf("\n"); a=1; b=num-i-1; }}Example Input/Output:
Input:
abcde
Output:
abcde
abcd*
*bcde
abc**
**cde
ab***
***de
a****
****e
*****
*****
#include<stdio.h>#include <stdlib.h>int main(){char str[1001];int len;scanf("%s%n",str,&len);int a=len,b=-1;for(int i=0;i<=len*2;i++){ for(int j=0;j<len;j++) { if(i%2==1) { if(j<a) printf("%c",str[j]); else printf("*"); } else { if(j>b) printf("%c",str[j]); else printf("*"); } } printf("\n"); if(i%2==0) a--; else b++;}}Example Input/Output:
Input:
3
all is well
Output:
aiw
lse
l*l
**l
Compiler#include<stdio.h>#include<string.h>int main() { int N; scanf("%d",&N); char str[N][101]; int len[N],max=0; for(int i=0;i<N;i++) { scanf("%s",str[i]); len[i]=strlen(str[i]); if(len[i]>max) max=len[i]; } for(int i=0;i<max;i++) { for(int j=0;j<N;j++) { if(i>(len[j]-1)) printf("*"); else printf("%c",str[j][i]); } printf("\n"); }}#include<stdio.h>#include <stdlib.h>int main(){int N;scanf("%d\n",&N);int arr[N],k=0;while(scanf("%d ",&arr[k++])>0);for(int i=1;i<=N;i++){if(N%i==0){int flag=0;for(int j=0;j<k;j++){if(i==arr[j]){flag=1;break;}}if(flag==0){printf("%d ",i);}}}}Example:
Input:
17
Output:
1111
Explanation:
The decimal value of 17((1*8^1)+(7*8^0)) is 15.
And the decimal value is converted to binary as 1111.
#include<stdio.h>#include<math.h>void binary(int n){ if(n!=0) { binary(n/2); printf("%d",n%2); }}int main() { char str[100]; int len,p=1; scanf("%s%n",str,&len); int decimal=0; for(int i=len-1;i>=0;i--) { int n=str[i]-'0'; if(i==len-1) { decimal=decimal+(n*1); } else { p=p*8; decimal=decimal+(n*p); } } binary(decimal);}Example:
Input:
0000skillrack
Output:
skillrack0000
#include<stdio.h>int main() {char str[1001];int len,count=0,index;scanf("%s%n",str,&len);for(int i=0;i<len;i++){if(str[i]!='0'){index=i;break;}count++;}printf("%s",&str[index]);for(int i=0;i<count;i++){printf("0");}}