Print the desired pattern shown in the example
INPUT-1:
5
OUTPUT-1:
1
2 a
3 b 1
4 c
5
INPUT-2:
9
OUTPUT-2:
1
2 a
3 b 1
4 c 2 a
5 d 3 b 1
6 e 4 c
7 f 5
8 g
9
import java.util.*;public class Hello { public static void main(String[] args) { //Your Code Here Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int ctr=1,flag=1; //System.out.printf("%c",ch+3-1); for(int row=1;row<=N;row++) { int temp=row; char ch=(char)('a'+row-2); if(ch>'z') ch='a'; for(int col=1;col<=ctr;col++) { if(col%2==1) { System.out.print(temp+" "); temp-=2; } else if(col%2==0) { System.out.printf("%c ",ch); ch-=2; } } if(row-1==N/2) flag=0; else if(flag==1) ctr++; if(flag==0) ctr--; System.out.println(); } }}Convert python code to c Example
Example INput and output:
INPUT:
5
1 1 1 1 0
1 1 1 0 0
1 1 1 0 0
1 0 1 1 1
1 1 1 0 1
OUTPUT:
9
INPUT:
2
0 0
0 0
OUTPUT:
0
import java.util.*;public class Hello { static int min(int num1,int num2){ return num1<num2?num1:num2; } static int max(int num1,int num2){ return num1>num2?num1:num2; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int [][]arr=new int[n][n]; int [][]dp=new int[n][n]; int result=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ arr[i][j]=sc.nextInt(); if(i==0||j==0) dp[i][j]=arr[i][j]; else if(arr[i-1][j]==1&&arr[i][j-1]==1&&arr[i-1][j-1]==1&&arr[i][j]==1) dp[i][j]=min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1])+1; else if(arr[i][j]==1) dp[i][j]=1; else dp[i][j]=0; result=max(result,dp[i][j]); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ System.out.print(dp[i][j]+" "); } System.out.println(); } System.out.print(result*result); }}Convert python code to c
N=int(input())numlist=[int(val)for val in input().split()]newlist=list(map(lambda x:x*2 if x%2==0 else x**2,numlist))print(*newlist)#include<stdio.h>void main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ int num; scanf("%d",&num); if(num%2) printf("%d ",num*num); else printf("%d ",num*2); }}The program must accept N integers and an integer k as the input.The program must print the sum of every K consecutive integers as the output.
Example input/output 1:
INPUT:
7
10 20 5 2 -5 66 -69
3
OUTPUT:
35 27 2 63 -8
Example input/output 2:
INPUT:
10
3 7 9 4 1 13 6 2 5 8
4
OUTPUT:
23 21 27 24 22 26 21
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String []str=new String[1000]; str=sc.nextLine().split(" "); int n=sc.nextInt(),k=n-1; for(int i=0;i<str.length;i++) { if(i==k) { StringBuilder a=new StringBuilder(str[i]); System.out.print(a.reverse()+" "); k=k+n; } else System.out.print(str[i]+" "); } }}The program must accept N integers and an integer k as the input.The program must print the sum of every K consecutive integers as the output.
Example input/output 1:
INPUT:
7
10 20 5 2 -5 66 -69
3
OUTPUT:
35 27 2 63 -8
Example input/output 2:
INPUT:
10
3 7 9 4 1 13 6 2 5 8
4
OUTPUT:
23 21 27 24 22 26 21
import java.util.Scanner;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int []arr=new int[n]; for(int i=0;i<n;i++) arr[i]=sc.nextInt(); int size=sc.nextInt(); for(int i=0;i<=n-size;i++) { int sum=0; for(int j=i;j<i+size;j++) sum+=arr[j]; System.out.print(sum+" "); } }}The program must accept an odd integer as the input and print the desired pattern as output as shown in the example section.
Note: Use _ for printing first line.
Example input/output 1:
INPUT:
3
OUTPUT:
____
\**/
*\/
Example input/output 2:
INPUT:
5
OUTPUT:
______
\****/
*\**/
**\/
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String str="_"; System.out.print(str.repeat(n+1)+"\n"); for(int i=0;i<(n+1)/2;i++) { for(int j=0;j<n;j++) { if(j==i) System.out.print("\\"); if(j==n-i-1) System.out.print("/"); if(j>=i&&j<n-1-i) System.out.print("*"); if(j<i) System.out.print("*"); } System.out.println(); } }}The program must accept the short code of a TV serial as the input.The format of the TV serial short code is "S followed by the season number E followed by the episode number". The program must expand and print the name of the TV serial as shown in the Example input/output section.
Note: The length of the TV serial short code is always 6.
Example input/output 1:
INPUT:
S02E05
OUTPUT:
Season 2, Episode 5
Example input/output 2:
INPUT:
S10E47
OUTPUT:
Season 10, Episode 47
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.next(); for(int i=1;i<s.length();i++) { if(s.charAt(i)=='E') { System.out.print("Season "+Integer.parseInt(s.substring(1,i))+", Episode "+Integer.parseInt(s.substring(i+1,s.length()))); break; } }}}The program for the flow chart
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x,y,z,max,isprint=0; x=sc.nextInt(); y=sc.nextInt(); z=sc.nextInt(); if(x>y) max=x; else max=y; int val=2; while(val<=max) { if(x%val==0&&y%val==0&&z%val!=0) { isprint=1; System.out.print(val+" "); } val++; } if(isprint==0) System.out.print("-1"); }}The program must accept an R and C and accept the given input and print the desired output as shown int the Example Input/Output.
Input:
5 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Output:
1 2 + 4 5
1 2 + 4 5
+ + + + +
1 2 + 4 5
1 2 + 4 5
Input:
3 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
Output:
1 2 + 4 5
+ + + + +
11 12 + 14 15
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int r,c; r=sc.nextInt(); c=sc.nextInt(); for(int row=0;row<r;row++) { for(int col=0;col<c;col++) { int num=sc.nextInt(); System.out.print((row==r/2||col==c/2)?"+ ":num+" "); } System.out.println(); } }}A table called laptop is created with the following DDL command:
CREATE TABLE laptop(id INT,name VARCHAR(100),price INT,processor VARCHAR(10),storage VARCHAR(10),ram VARCHAR(10));
Write the SQL query to select the id,name,price,processor,storage,ram from the table laptop where price is then 40000,the processor is equal to 'Core i5', the storage is equal to '1TB' and the ram is equal to '8GB'.
Note:The id of the laptops must be sorted in ascending order.
select * from mobile where imei like '%545%' order by id;The program must accept an even number as the input and print the desired pattern as shown in the example input/output.
Input:
6
Output:
1 2 3 6 5 4
* 1 2 4 3
* * 1 2
Input:
8
Output:
1 2 3 4 8 7 6 5
* 1 2 3 6 5 4
* * 1 2 4 3
* * * 1 2
#include<stdio.h>#include <stdlib.h>int main(){int size;scanf("%d",&size);int ctr=size,temp=size,secondhalf=size;for(int i=0;i<size/2;i++){ int first=1; for(int j=0;j<temp;j++) { if(j>=i) { if(j<=(size/2)-1) { printf("%d ",first); first++; } else { printf("%d ",secondhalf); secondhalf--; } } else printf("* "); } printf("\n"); ctr-=2; secondhalf=ctr; temp--;}}complete the getRepeatedString to run successfully.
Input:
code
Output:
ccooddee
Input:
gmail
Output:
ggmmaaiill
char* getRepeatedString(char str[]){ long int i=0,len=strlen(str);char *temp=malloc(sizeof(char)*(len*3));for(long int index=0;index<len;index++){ temp[i++]=str[index]; temp[i++]=str[index];}temp[i]=NULL;return temp;}A table called laptop is created with the following DDL command:
CREATE TABLE laptop(id INT,name VARCHAR(100),price INT,processor VARCHAR(10),storage VARCHAR(10),ram VARCHAR(10));
Write the SQL query to select the id,name,price,processor,storage,ram from the table laptop where price is then 40000,the processor is equal to 'Core i5', the storage is equal to '1TB' and the ram is equal to '8GB'.
Note:The id of the laptops must be sorted in ascending order.
select * from laptop where price<40000 and processor ='Core i5' and storage ='1TB' and ram='8GB' order by id;Flow chart
#include<stdio.h>#include <stdlib.h>int main(){int x,y;scanf("%d%d",&x,&y);while(x<y){ printf("%d%d",x%10,y%10); x/=10; y/=10;}}The program must accept a string S containing only lower case alphabets as the input.The program must print all the palindromic sub string values of length 3 in the string S as the output.If there is no such palindrome sub string the program must print -1 as the output.
Input:
eyelens
Output:
eye
ele
Input:
skillrack
Output:
-1
#include<stdio.h>#include <stdlib.h>void print(char str[],int start,int end){ for(;start<=end;start++) printf("%c",str[start]); printf("\n");}int main(){char str[100];int len,ctr=0;scanf("%s%n",str,&len);for(int i=0;i<len-2;i++){ if(str[i]==str[i+2]) { print(str,i,i+2); ctr=1; }}(ctr==0)&&(printf("-1"));}A table called event is created with the following DDL command:
CREATE TABLE event(id INT,title VARCHAR(100),type VARCHAR(10),attendeescount INT,active BOOLEAN);
Write the SQL query to select the id,title and attendeescount from the table event where active is equal to 'True',type is equal to 'TECH' and attendeescount is greater than 50.
Note:The id of the events must be sorted in ascending order.
select* from player where odimatches >10 and testmatches >10 and t20imatches >10 order by name;flow chart
#include<stdio.h>#include <stdlib.h>int main(){int x,y;scanf("%d %d",&x,&y);int ctr=x;while(ctr<=y){ if(!(ctr%x)) ctr++; else if(ctr%10==y%10) ctr++; else { printf("%d ",ctr); ctr++; }}}Please convert the following C code to python so that the python program executes succesfully passing the test cases.
#include<stdio.h>#include<stdlib.h>int main(){int x,y;scanf("%d%d",&x,&y);char floatval[11];double val;sprintf(floatval,"%d.%d",x,y);sscanf(flatval,"%lf",&val);printf("%.2lf",val);return 0;x,y=input().split()print('%.2f'%float(x+'.'+y))Please convert the following Python code to C so that the C program executes succesfully passing the test cases.
N=int(input())numList=list(map(int,input().split()))numList=sorted(numList,key=lambda num:bin(num).count("1"))print(*numList);#include<stdio.h>struct pair{ int num; int count1;};int bin(int num){ int count1=0; while(num!=0) { if(num%2) count1++; num/=2; } return count1;}int* array(struct pair a[],int N,int max){ int*arr=malloc(sizeof(int)*N),count=0,j=0; while(count<=max) { for(int i=0;i<N;i++) { if(a[i].count1==count) arr[j++]=a[i].num; } count++; } return arr;}int main(){ int N,max=0; scanf("%d",&N); struct pair a[N]; for(int i=0;i<N;i++) { scanf("%d",&a[i].num); a[i].count1=bin(a[i].num); if(a[i].count1>max) max=a[i].count1; } int*newArray=array(a,N,max); for(int i=0;i<N;i++) printf("%d ",newArray[i]);}The program must accept N integers as the input.For each integer X among the N integers,the program must double the integer X.For each odd integers Y among the N integers,the program must print the sum of N integers as the output.
Input:
4
5 2 8 7
Output:
68
Explanation:
Hence output is 68.
Input:
5
4 9 1 1 8
Output:
68
#include<stdio.h>#include <stdlib.h>int main(){int N,sum=0;scanf("%d",&N);for(int i=0;i<N;i++){ int num; scanf("%d",&num); if(num&1) sum+=(num*4); else sum+=(num*2);}printf("%d",sum);}The program must accept N integer and an integer X as the input.The program must print the sum of integers ending with X among the N integers as the output.If there is no such integer the program must print 0 as the output.
Input:
5 4
87 54 15 984 104
Output:
1142
Input:
4 87
187 787 154 978
Output:
95974
Input:
6 400
6500 98 2 540 12 14
Output:
0
#include<stdio.h>#include<math.h>int main() { int N,X; scanf("%d %d",&N,&X); int sum=0,length=log10(X)+1,divide=pow(10,length); for(int i=0;i<N;i++) { int num; scanf("%d",&num); if(num%divide==X) sum+=num; } printf("%d",sum);}The length of one side S ( in cm) of a rectangle and its perimeter P(in cm) are passed as the input.The program must print the length of another side of the rectangle with the precision up to two decimal places as the output.
Formula:
Input:
4 18
Output:
5.00
Input:
3 15
Output:
4.50
#include<stdio.h>int main() {int side,peri;scanf("%d%d",&side,&peri);printf("%.2f",(peri/2.0)-side);}A table called event is created with the following DDL command:
CREATE TABLE event(id INT,title VARCHAR(100),type VARCHAR(10),attendeescount INT,active BOOLEAN);
Write the SQL query to select the id,title and attendeescount from the table event where active is equal to 'True',type is equal to 'TECH' and attendeescount is greater than 50.
Note:The id of the events must be sorted in ascending order.
select id,title,attendeescount from event where active='true' and type='TECH' and attendeescount>50 order by id;The program must accept two string values S1 and S2 are of equal length as the input. The string S1 contains only alphabets and the string S2 contains u or l in both lower case and upper case) For each alphabet CH in the string S2, the program must Toggle the case of the alphabet at the same position in the string S1 based on the following conditions
- If CH is u or U, the program must convert the corresponding alphabet in S1 to upper case
If CH is I or L the program must convert the corresponding alphabet in S1 to lower case
Finally, the program must print the modified string S1 as the output
Example Input/Output 1:
Input
book
ULIU SECE
Output
Book
Explanation:
The first alphabet in S2 is u. So the first alphabet in S1 must be in the upper case.
Now the S1 becomes Book
The second alphabet in S2 is L So the second alphabet in S1 must be in the lower case.
Now the S1 remains the same Book (as o is already in lower case)
The third alphabet in S2 ist. So the third alphabet in S1 must be in the lower case.
Now the S1 remains the same Book (as o is already in lower case)
The fourth alphabet in S2 is U So the fourth alphabet in S1 must be in the upper case
Now the S1 becomes Book
Hence the output is Book
Example Input/Output 2:
G00OOGLE
lululUUL
Output
gOoOoGLe
#include<stdio.h>#include <stdlib.h>int main(){char str1[1001],str2[1001];scanf("%s %s",str1,str2);for(int i=0;i<strlen(str2);i++){ if(tolower(str2[i])=='u') str1[i]=toupper(str1[i]); else str1[i]=tolower(str1[i]);}printf("%s",str1);}You must implement the function getStringOfABC(int N) which accepts an integer N as the input.The function must form a string S of length N based on the following condition.
Example Input/Output 1:
Input:
5
Output:
abcab
Input:
9
Output:
abcabcabc
#include<stdio.h>#include<stdlib.h>char* getStringOfABC(int N){char *str,a='a';str=malloc(sizeof(char)*N);int i=0;while(i<N){ if(a=='c') { str[i]=a; a='a'; } else if(a!='c'){ str[i]=a; a++; } i++;}str[N]='\0';return str;}int main() { int N; scanf("%d", &N); char *str = getStringOfABC(N); printf(str); free(str); return 0; }The program for the given flow chart.
import java.util.*;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(),y=sc.nextInt(); int ctr1=1,ctr2=y; while(ctr1<=x||ctr2>=1) { if(ctr1<=x) { System.out.print(ctr1+" "); ctr1++; } if(ctr2>=1) { System.out.print(ctr2+" "); ctr2--; } } }}The program must accept an integer N as the input and print the desired pattern as shown in the Example
Input:
5
Output:
1
2 5
3 4 1
4 3 2 5
5 2 3 4 1
Input:
8
Output:
1
2 8
3 7 1
4 6 2 8
5 5 3 7 1
6 4 4 6 2 8
7 3 5 5 3 7 1
8 2 6 4 4 6 2 8
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int arr[n][n],num=1;for(int col=0;col<n;col++){ for(int row=col;row<n;row++) { arr[row][col]=num; if(col%2) --num; else num++; } if(col%2) num=1; else num=n;}for(int row=0;row<n;row++){ for(int col=0;col<=row;col++) { printf("%d ",arr[row][col]); } printf("\n");}}The program must accept a integer N as the input and print the maximum number that can be formed only by means of rotating the number clockwise.
Input:
4654
Output:
6544
Input:
12458
Output:
81245
#include<stdio.h>#include <stdlib.h>int main(){int n,x,c,sum=0;scanf("%d %d %d",&n,&x,&c);for(int i=0;i<n;i++){ int num; scanf("%d ",&num); sum+=(num>x?(num+c):num);}printf("%d",sum);}The program must accept an integer N as the input and make the integer as maximum possible number by rounding clockwise and print final maximum number output.
Input:
4654
Output:
6544
Input:
12458
Output:
81245
#include<stdio.h>#include<stdlib.h>#include<string.h>int main() { char str[100]; int len,max=0; scanf("%s%n",str,&len); while(len) { char temp=str[0]; for(int i=0;i<strlen(str)-1;i++) str[i]=str[i+1]; str[strlen(str)-1]=temp; int num=atoi(str); if(num>max) max=num; len--; } printf("%d",max);}The program must accept N integers as the input.The program must print the integers which are having the same digit among the N integers as the output.If there is no such integer,the program must print -1 as the output.
Input:
4
87 222 9999 1
Output:
222 9999 1
Input:
5
887 56566 122 10000 56
Output:
-1
#include<stdio.h>#include <stdlib.h>int main(){int n,ctr=0;scanf("%d\n",&n);for(int i=0;i<n;i++){ int num; scanf("%d ",&num); int flag=0,check=num%10,temp=num; while(temp!=0) { if(temp%10!=check) flag=1; temp/=10; } if(!flag) { printf("%d ",num); ctr=1; }}if(!ctr)printf("-1");}A table called bus is created with the following DDL command:
CREATE TABLE bus(id INT,busregistrationnum VARCHAR(20),source VARCHAR(30),destination VARCHAR(30),ac BOOLEAN,slpeer BOOLEAN,seater BOOLEAN);
Write the SQL query to select the id,,busregistrationnum from the table bus where ac is equal to 'False',sleeper is equal to 'True' and seater is equal to 'True'.
Note:The id of the bus must be sorted in alphabetical order.
select id,busregistrationnum from bus where ac='False'and sleeper='True' and seater='True'order by id;Please convert the following C code to Python so that the Python program executes successfully passing the test cases.
#include<stdio.h>#include<stdlib.h>int main(){int N;scanf("%i",&N);printf("%i",N);return 0;}x=input()if x[0]=='0': if x[1]=='x'or x[1]=='X': print('%d'%int(x,16)) else: print('%d'%int(x,8))else: print(x)You must implement the function hidePassword(char str[]) which accepts a string str as the input.The function must calculate the number of alphabets A in the str and the number of digits D in str.Then the function must modify the string str by replacing each alphabet by *(asterisk) if A is greater than or equal to D.Else the function must modify the string str by replacing each digit by *(asterisk).
Input:
s1r2a3ck
Output:
*1*2*3**
Input:
123ABCD007
Output:
***ABCD***
void hidePassword(char str[]){ int countdigit=0,countalpha=0; for(int i=0;i<strlen(str);i++) { if(isalpha(str[i])) countalpha++; else if(isdigit(str[i])) countdigit++; } int j=0; if(countalpha>=countdigit) { j=1; } for(int i=0;i<strlen(str);i++) { if(j==1) { if(isalpha(str[i])) str[i]='*'; } else { if(isdigit(str[i])) str[i]='*'; } }}The program must accept a integer matrix of size RxC as the input.The program must print the sum of integers in the bottom-right quadrant of the matrix as the output.
Note: R and C are always even integers.
Input:
4 4
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
Output:
18
Explanation:
The integer in the bottom -right quadrant of the matrix are 2 3 6 7.So the sum of those integers is 18(2+3+6+7)
Hence the output is 18.
Input:
6 2
5 7
4 4
8 3
1 5
9 7
2 1
Output:
13
#include<stdio.h>#include <stdlib.h>int main(){int r,c;scanf("%d %d\n",&r,&c);int arr[r][c],sum=0;for(int row=0;row<r;row++){ for(int col=0;col<c;col++) { scanf("%d ",&arr[row][col]); if(row>=r/2&&col>=c/2) sum+=arr[row][col]; }}printf("%d",sum);}The program must accept N integers as the input.The program must print the sum of digits in the octal representation of N as the output.
Input:
12
Output:
5
Explanation:
The octal representation of 12 is 14.
The sum of digits in 14 is 5.
Hence the output is 5.
Input:
9
Output:
2
#include<stdio.h>#include <stdlib.h>int sum=0;void octal(int n){ if(n!=0) { octal(n/8); sum+=n%8; }}int main(){int n;scanf("%d",&n);octal(n);printf("%d",sum);}A table called donor is created with the following DDL command:
CREATE TABLE donor(id INT,name VARCHAR(20),bloodgroup VARCHAR(3));
Write the SQL query to select the id,name,bloodgroup from the table donor where bloodgroup is not equal to'AB+'.
Note:The name of the donors must be sorted in alphabetical order.
select id,name,bloodgroup from donor where bloodgroup !='AB+' order by name;The program must accept N integers as the input.The program must form a binary representation B of length N by concatenating 1s and 0s alternatively.Then the program must print the decimal equivalent of B as the output.
Input:
5
Output:
21
Explanation:
The binary representation of B is 10101(alternative 1s and 0s of length N)
Input:
8
Output:
170
Explanation:
The binary representation of B is 10101010(alternative 1s and 0s of length N)
#include<stdio.h>#include <stdlib.h>int main(){int num,count1,ctr=1;long long int sum=0;scanf("%d",&num);count1=num/2;if(num&1){ count1=(num/2)+1; ctr=0;}while(count1){ sum+=(long long int)(pow(2,ctr)); ctr+=2; count1--;}printf("%lld",sum);}The program must accept N integers as the input.The program must sum the integers having odd digits.And the final sum is printed as output.
Note:If there is no integer having odd digit print 0 as output
Input:
5
13 888 1005 102 8
Output:
998
Input:
4
12 4568 32 758475
Output:
0
#include<stdio.h>#include <stdlib.h>int main(){int a;scanf("%d\n",&a);int num,len,sum=0;for(int i=0;i<a;i++){ scanf("%d%n\n",&num,&len); if(len%2) sum+=num;}printf("%d",sum);}The program must accept a string S as e input.The program mut print the desired pttern as shown in the eexample.
Input:
skillrack
Output:
skillrack
*killrac*
**illra**
***llr***
****l****
***llr***
**illra**
*killrac*
skillrack
Input:
logics
Output:
logics
*ogic*
**gi**
*ogic*
logics
#include<stdio.h>#include <stdlib.h>int main(){char str[1001];int len;scanf("%s%n",str,&len);int start=-1,end=len,ctr=1;while(1){ for(int index=0;index<len;index++) { if(index<=start||index>=end) printf("*"); else printf("%c",str[index]); } printf("\n"); if(ctr) { start++; end--; } else { start--; end++; } if((start+3)>=end&&len%2==0) ctr=0; else if((start+2)>=end&&len%2==1) ctr=0; if(end-1==len) break;}}The program must accept two string values U and P as the input U represents the username of a digital locker and P represents its password.The program must print VALID if the password does not contain any characters from the username U.Else the program must print INVALID as the output.
Input:
uit047@demo
srack123
Output:
VALID
Input:
AVNG007_bk47
c7sz0ct2o19
Output:
INVALID
#include<stdio.h>#include <stdlib.h>int main(){char user[51],pass[21];scanf("%s\n%s",user,pass);int flag=0;for(int i=0;i<pass[i]!='\0';i++){ for(int j=0;j<user[j]!='\0';j++) { if(pass[i]==user[j]) { flag=1; break; } }}if(flag) printf("INVALID");else printf("VALID");}The program must accept an integer N as the input.The program must split the integer N int three-digit integers(every three consecutive digits).Then the program must print the sum S of those three-digit integers as the output.
Input:
210045
Output:
255
Explanation:
Input:
100100
Output:
200
#include<stdio.h>int main() { int x; scanf("%d",&x); int sum=0; while(x!=0) { sum+=x%1000; x/=1000; } printf("%d",sum);}The program must accept an integer N as the input.The program must print N characters from the string"abcd" circularly in the clockwise direction as the output.
Input:
5
Output:
abcda
Input:
10
Output:
abcdabcdab
#include<stdio.h>#include <stdlib.h>int main(){int n;char str[]="abcd";scanf("%d",&n);for(int i=0;i<n/4;i++) printf("%s",str);for(int i=0;i<n%4;i++) printf("%c",str[i]);}The program must accept a time T(in 24hr format HH:MM) and an integer X as the input.The program must update the time T by adding X minutes to it .Then the program must print the updated time T in the same 24hr format as the output.
Input:
08:15
Output:
08:35
Input:
23:50
15
Output:
00:05
Input:
13:45
102
Output:
15:27
#include<stdio.h>#include <stdlib.h>int main(){int h,m,x;scanf("%d:%d",&h,&m);scanf("\n%d",&x);int minutes=(h*60)+m+x;int hour=(minutes/60)%24;int min=minutes%60;if(hour<10) printf("0%d:",hour);else printf("%d:",hour);if(min<10) printf("0%d",min);else printf("%d",min);}The program must accept two integers N and X as the input.The program must print the integers from 1 to N based on the following conditions.
Input:
10 5
Output:
1 1 2 2 3 3 4 4 5 5 6 7 8 9 10
EXPLANATION:
Here X is positive integer.So the first 5 integers are repeated twice from 1 to 10.
Hence the output is 1 1 2 2 3 3 4 4 5 5 6 7 8 9 10
Input:
10 -5
Output:
1 2 3 4 5 6 6 7 7 8 8 9 9 10 10
#include<stdio.h>#include <stdlib.h>int main(){int n,x;scanf("%d %d",&n,&x);for(int i=1;i<=n;i++){ if(x>0&&i<=x) printf("%d %d ",i,i); else if(x<0&&i>(n+x)) printf("%d %d ",i,i); else printf("%d ",i);}}The program must accept three integers X,Y and Z as the input.The program must find and print the smallest positive integer N based on the following conditions:
Input:
2 8 2
Output:
10
EXPLANATION:
10 is the smallest integer which is divisible by 2 and it is not equal to any integers from 2 to 8.So 10 is printed as the output.
Input:
5 10 4
Output:
4
#include<stdio.h>#include <stdlib.h>int main(){int x,y,z;scanf("%d %d %d",&x,&y,&z);int n;if(z<x) n=1;else n=y+1;while(1){ if(n%z==0) { printf("%d",n); break; } n++;} }There are five bags in a row where each bag contains gold coins.The number of gold coins in each bag is passed as the input.The program must print the maximum number of gold coins by choosing any two consecutive bags as the output.
Input:
1 2 3 4 5
Output:
9
Input:
9 0 8 4 1
Output:
12
#include<stdio.h>#include <stdlib.h>int main(){int max=0,prev=0,pre;for(int i=0;i<5;i++){ scanf("%d ",&pre); ((pre+prev)>max)&&(max=pre+prev); prev=pre;}printf("%d",max);}The program must accept the area of a square A(in cm2) as the input.The program must divide the square int four equal squares.Then the program must print the side(in cm) of any one of the squares with the precision up to two decimal as the output.
Input:
16
Output:
2.00
Input:
14
Output:
1.87
import java.util.*;import java.lang.Math;public class Hello { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.format("%.2f",Math.sqrt(sc.nextDouble()/4)); }}The program must accept a string S containing only lower case alphabets as the input.For each vowel CH in the string S(from left to right),the program must remove the next character of CH from the string s.Then the program must print the modified string as the output.
Input:
skillrack
Output:
skilrak
Input:
aerospace
Output:
aropae
#include<stdio.h>#include <stdlib.h>int main(){char a[1001];scanf("%s",a);for(int i=0;i<strlen(a);i++){ char ch=tolower(a[i]); printf("%c",a[i]); if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') { i++; }}}The program must accept an integer matrix of size RxC as the input.The program must print the mirror image of the matrix as the output.
Input:
2 3
1 2 3
4 5 6
Output:
3 2 1
6 5 4
Input:
2 2
01 02
03 04
Output:
20 10
40 30
#include<stdio.h>#include <stdlib.h>#include<string.h>int main(){int r,c;scanf("%d %d\n",&r,&c);char mat[r][c][100];for(int row=0;row<r;row++){ for(int col=0;col<c;col++) { scanf("%s ",mat[row][col]); }}for(int row=0;row<r;row++){ for(int col=c-1;col>=0;col--) { for(int i=strlen(mat[row][col])-1;i>=0;i--) printf("%c",mat[row][col][i]); printf(" "); } printf("\n");}}A table called debtor is created with the following DDL command
Write the SQL query to delete the records of the debtor who have paid off the entire loan amount (i.e, Delete all the debtors who have their currentbalance as 0.)
delete debtor where currentbalance=0;The program must accept four integers as the input.The program must print YES if the sum of any two integers is equal to the sum of the remaining integers.Else the program must print NO as the output.
Input:
2 3 1 4
Output:
YES
Explanation:
The sum of 2 and 3 is 5.
The sum of 1 and 4 is 5.
Here,both results are the same.Hence the output is YES.
Input:
3 5 8 2
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){int num1,num2,num3,num4;scanf("%d %d %d %d",&num1,&num2,&num3,&num4);if(num1+num2==num3+num4) printf("YES");else if(num1+num3==num2+num4) printf("YES");else if(num1+num4==num2+num3) printf("YES");else printf("NO"); }The program must accept a string S containing only alphabets as the input.The program must print YES if all the vowels in the string S are same case(either upper case or lower case).Else the program must print NO as the output.
Input:
SkillRack
Output:
YES
Explanation:
The string SkillRack contains two vowels i and a.Here i and a are in lower case.So YES is printed as the output.
Input:
Information
Output:
NO
#include<stdio.h>#include <stdlib.h>int main(){char str[1001];scanf("%s",str);int scount=0,ccount=0;for(int i=0;i<strlen(str);i++){ char a=str[i]; if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u') scount++; else if(a=='A'||a=='E'||a=='I'||a=='O'||a=='U') ccount++;}if(scount>0&&ccount==0) printf("YES");else if(ccount>0&&scount==0) printf("YES");else printf("NO"); }A table called customer is created with the following DDL command
Write the SQL query to select the branchname and its sum of loanamount from the table customer.
Note: The total loanamount of the branches must be sorted in descending order.
select branchname,sum(loanamount) as a from customer group by branchnameorder by a desc;The program must accept two characters CH1 and CH2 as the input.The program must print all the ASCII values from the ASCII of CH1 to the ASCII of CH2 as the output.
Input:
a e
Output:
97 98 99 100 101
Explanation:
Here CH1=a and CH2=e.
The ASCII value of a is 97 and the ASCII value of e is 101.
Hence the output is 97 98 99 100 101
Input:
5 3
Output:
15
#include<stdio.h>#include <stdlib.h>int main(){char ch1,ch2;scanf("%c %c",&ch1,&ch2);for(;ch1<=ch2;ch1++){ printf("%d ",ch1);}}A table called student is created with the following DDL command
Write the SQL query to list all the arrearscount along with the number of students having that arrearscount from the table student.
Note: The arrearscount must be sorted in descending order.
select arrearscount,count(regnum) from student group by arrearscount order by arrearscount desc;(29/11/2019) Write the code for the given flow diagram
#include<stdio.h>#include <stdlib.h>int main(){int a,b;scanf("%d %d",&a,&b);a=a-(a%b);while(1){ if(a>0) { printf("%d ",a); a=a-b; } else { return 0; }}}A table called player is created with the following DDL command
Write the SQL query to list all the countries along with their total medals from the table player.
Note: The total medals of the countries must be sorted in descending order.
select country,sum(medalscount) as a from player group by country order by a desc;The program must accept the factor of an integer N(excluding 1 and N)as the input.The program must find the integer N from its factors and print it as the output.
Input:
8 2 6 12 4 3
16
Output:
24
Explanation:
The factors of 24 are 2,3,4,6,8 and 12(excluding 1 and 24).Here the given factors are the factors of 24.So 24 is printed as the output.
Input:
5 3
Output:
15
#include<stdio.h>#include <stdlib.h>int main(){int a,min,max=0;while(scanf("%d",&a)>0){ (max==0)&&(min=a); (a<min)&&(min=a); (a>max)&&(max=a);}printf("%d",min*max);}A table called employee is created with the following DDL command
Write the SQL query to update the salary of all the employees by adding the overtime*50 to the salary.
UPDATE employee SET salary=salary+overtime*50;The program must accept three integers X ,Y and Z as the input.The program must print their sum if all the three integers are even Else the program,use print their product as the output.
Input:
10 2 4
16
Output:
10 12 8 195
Explanation:
Here all the integers are even ,so their sum 16(10+2+4) is printed as the output.
Input:
5 5 10
Output:
250
#include<stdio.h>#include <stdlib.h>int main(){long int a,b,c;scanf("%ld %ld %ld",&a,&b,&c);(a%2==0&&b%2==0&&c%2==0)&&(printf("%ld",a+b+c));(a%2!=0||b%2!=0||c%2!=0)&&(printf("%ld",a*b*c));}A table called Person is created with the following DDL command
Write the SQL query to select id,name and bloodgroup from the table person where age is between 18 and 65(excluding 18 and 65) and weight is greater than 50
Note:The id of the person must be sorted in ascending order.
SELECT id,name,bloodgroup FROM person WHERE age>18 AND age<65 AND weight >50 ORDER BY id;The program must accept N integers as the input.The program must print the integers that are divisible by the sum of the digits among the N integers .If there is no such integer then the program must print -1 as the output.
Input:
5
10 14 12 8 195
Output:
10 12 8 195
Explanation:
The first integer 10 is divisible by 1(1+0).So 10 is printed.
The second integer 14 is not divisible by 5(1+4).So 14 is not printed.
The third integer 12 is divisible by 3(1+2).So 12 is printed.
The fourth integer 8 is divisible by 8(8).So 8 is printed.
The fifth integer 195 is divisible by 15(1+9+5).So 195 is printed.
Input:
3
545 13 66
Output:
-1
#include<stdio.h>#include <stdlib.h>int main(){int n;scanf("%d",&n);int a[n],count=0;for(int i=0;i<n;i++){ scanf("%d ",&a[i]); int temp=a[i]; int sum=0; while(temp!=0) { sum+=temp%10; temp/=10; } (a[i]%sum==0) && printf("%d ",a[i]) && (count=1);}(count==0)&& printf("-1");}A table called clothing is created with the following DDL command:
Write the SQL query to select name,publishedyear and price from the table clothing where the publishedyear is greater than 2010.
Note: The publishedyear of the clothing must be sorted in descending order.
SELECT name,publishedyear,price FROM clothing WHERE publishedyear > 2010 ORDER BY publishedyear DESC;The program must accept a string S as the input.The program must print YES if all the characters in the string S are same.Else the program must print NO as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
aaaaaaaaaaaa
OUTPUT
YES
EXAMPLE INPUT/OUTPUT 2:
INPUT:
bbbbbbbbbbbbbccccccc
OUTPUT
NO
#include<stdio.h>#include <stdlib.h>int main(){char a[1000];scanf("%s",a);for(int i=1;i<strlen(a);i++){ if(a[0]!=a[i]) { printf("NO"); return 0; }}printf("YES");}The program must accept a string S as the input.The program must print VALID if any of the following conditions are true.
The program must print INVALID if none of the conditions are true as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
SKILLRACK
OUTPUT
VALID
EXAMPLE INPUT/OUTPUT 2:
INPUT:
skillrack
OUTPUT
VALID
EXAMPLE INPUT/OUTPUT 3:
INPUT:
Skillrack
OUTPUT
VALID
EXAMPLE INPUT/OUTPUT 4:
INPUT:
SkillRack
OUTPUT
INVALID
#include<stdio.h>#include <stdlib.h>int main(){char s[1000];int len,ucount=0,lcount=0;scanf("%s%n",s,&len);for(int i=0;i<len;i++){ if(s[i]>=65&&s[i]<=90) ucount++; else if(s[i]>=97&&s[i]<=122) lcount++;}if(lcount==len||ucount==len||((s[0]<97)&&(lcount==len-1))) printf("VALID");else printf("INVALID");}The program must accept an two integer X and Y as the input.The program must print all the palindromic integers from X to Y as the output.If there is no palindrome integers from X to Y then the program must print -1 as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
120 191
OUTPUT
121 131 141 151 161 171 181 191
EXAMPLE INPUT/OUTPUT 2:
INPUT:
455 46
OUTPUT
-1
#include<stdio.h>#include <stdlib.h>int main(){ int n1,n2,count=0; scanf("%d %d",&n1,&n2);for(int i=n1;i<=n2;i++){ int len=0,a[1000],num=i,flag=0; while(num>0) { a[len++]=num%10; num=num/10; } for(int j=0;j<len;j++) { if(a[j]!=a[len-j-1]) { flag=1; break; } } if(flag==0) { printf("%d ",i); count=1; } }if(count==0) printf("-1");}#include <stdio.h>#include <string.h>int main(){ int n1,n2,count=0; scanf("%d %d",&n1,&n2); for(int i=n1;i<=n2;i++) { int num=i,len=0; char a[1000],b[1000]; sprintf(b,"%d",i); while(num!=0) { a[len++]=(num%10)+'0'; num/=10; } a[len]=NULL; if(strcmp(b,a)==0) { printf("%s ",a); count=1; } } if(count==0) printf("-1");}The program must accept an integer N representing a power of 2 as the input..The program must print the expression E which represents the product of 2s for the given integer N as the output.
Note: The water can not be drained from any tank.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
8
OUTPUT
2*2*2
Explanation:
Here 8=2^3.
Hence output is 2*2*2.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
512
OUTPUT
2*2*2*2*2*2*2*2*2
#include<stdio.h>int main() { int n,i=1; scanf("%d",&n); while(1) { if(n==(1<<i)) { printf("2"); return 0; } else printf("2*"); i++; }}There are three water tanks A,B,C are filled with X,Y and Z liters of water respectively.The values of X,Y and Z are passed as the input to the program.The program must print the minimum quantity of additional water(in liters) is required to fill all three tanks with equal water.
Note: The water can not be drained from any tank.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
5 10 7
OUTPUT
8
Explanation:
The tank A requires 5 litres of water and tank C requires 3 litres of water to make all the three tanks equal.
The minimum quantity of water required is 8(5+3).So 8 is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
5 5 1
OUTPUT
4
EXAMPLE INPUT/OUTPUT 3:
INPUT:
9 9 9
OUTPUT
0
#include<stdio.h>#include <stdlib.h>int main(){int X,Y,Z,max;scanf("%d %d %d",&X,&Y,&Z);max=X;(Y>max)&&(max=Y);(Z>max)&&(max=Z);printf("%d",(max-X)+(max-Y)+(max-Z));}There are X kgs of Apple,Y kgs of Banana and Z kgs of watermelon in a fruit shop.To prepare a box of fruit salad(7kgs),the fruits are required in the ratio of 1:2:4(Apple : Banana : Watermelon).The program must print the maximum number of boxes of fruit salad that can be prepared from the given quantity of fruits as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
2 5 7
OUTPUT
1
EXAMPLE INPUT/OUTPUT 2:
INPUT:
4 8 14
OUTPUT
3
#include<stdio.h>#include <stdlib.h>int main(){int X,Y,Z,count=0;scanf("%d %d %d",&X,&Y,&Z);while(1){ if(X>=1&&Y>=2&&Z>=4) { count++; X-=1; Y-=2; Z-=4; } else { printf("%d",count); return 0; }}}The program must accept two prime numbers X and Y as the input.The program must print YES if Y is the next immediate prime number of X.Else the program must print NO as the output
EXAMPLE INPUT/OUTPUT 1:
INPUT:
2 3
OUTPUT
YES
EXAMPLE INPUT/OUTPUT 2:
INPUT:
7 11
OUTPUT
YES
EXAMPLE INPUT/OUTPUT 3:
INPUT:
13 19
OUTPUT
NO
#include<stdio.h>#include <stdlib.h>int main(){int X,Y,nxt;scanf("%d %d",&X,&Y);nxt=X+1;while(1){ int flag=0; for(int i=2;i<nxt/2;i++) { if(nxt%i==0) { flag=1; } } if(flag==0) { if(nxt==Y) { printf("YES"); return 0; } else { printf("NO"); return 0; } } nxt++;}}The program must accept an integer N as the input. The program must generate a sequence of integer containing the integers from 1 to N.Then the program must invert the sign of all the powers of 2 in the generated sequence.Finally the program must print the sum of all the integers in the modifies sequence as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
4
OUTPUT
-4
Explanation:
Here N=4.So the sequence is 1 2 3 4
After inverting the sign of all the power of 2 the sequence becomes -1 -2 3 -4
Now the sum of integers in the sequence is -4
Hence -4 is printed as output
EXAMPLE INPUT/OUTPUT 2:
INPUT:
10
OUTPUT
25
#include<stdio.h>#include <stdlib.h>int main(){int n,sum=0,sqr=1;scanf("%d",&n);for(int i=1;i<=n;i++){ if(i==sqr) { sum-=i; sqr*=2; } else { sum+=i; }}printf("%d",sum);}(13/11/2019 )The program must accept an string S representing an integer in words as the input.The program must print the corresponding digit for each word in S as the output.The words and their equivalent digits are given below:
zero-0
one-1
two-2
three-3
four-4
five-4
six-6
seven-7
eight-8
nine-9
EXAMPLE INPUT/OUTPUT 1:
INPUT:
one five seven
OUTPUT
157
EXAMPLE INPUT/OUTPUT 2:
INPUT:
four nine nine zero eight one
OUTPUT:
499081
#include<stdio.h>#include <stdlib.h>int main(){char a[100];while(scanf("%s",a)>0){ if(strcmp(a,"zero")==0) { printf("0"); } else if(strcmp(a,"one")==0) { printf("1"); } else if(strcmp(a,"two")==0) { printf("2"); } else if(strcmp(a,"three")==0) { printf("3"); } else if(strcmp(a,"four")==0) { printf("4"); } else if(strcmp(a,"five")==0) { printf("5"); } else if(strcmp(a,"six")==0) { printf("6"); } else if(strcmp(a,"seven")==0) { printf("7"); } else if(strcmp(a,"eight")==0) { printf("8"); } else { printf("9"); }}}(12/11/2019 )The program must accept an integer X, Y and Z as the input.The program must print the GCD(Greatest Common Divisor)of X , Y and Z as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
70 100 50
OUTPUT
10
EXAMPLE INPUT/OUTPUT 2:
INPUT:
26 25 13
OUTPUT
13
#include<stdio.h>#include <stdlib.h>int main(){int a,b,c,gcd;scanf("%d %d %d",&a,&b,&c);int max=a;if(b>max&&b>c) max=b;else if(c>max&&c>b) max=c;for(int i=1;i<=max;i++){ if(a%i==0&&b%i==0&&c%i==0) gcd=i;}printf("%d",gcd);}(11/11/2019 )The program must accept an string Str as an input.The program must print it's character CH as the output based on certain condition as given below.
If a character CH is a digit then the character CH is print as same as that on output.
If a character CH is a alpha then the ASCII value of that character is print as an output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
a1b1c1
OUTPUT
97 1 98 1 99 1
EXAMPLE INPUT/OUTPUT 2:
INPUT:
123895
OUTPUT
1 2 3 8 9 5
#include<stdio.h>#include <stdlib.h>#include<string.h>int main(){char a[1001];scanf("%s",a);for(int i=0;i<strlen(a);i++){ if(isdigit(a[i])) { printf("%c ",a[i]); } else { printf("%d ",a[i]); }}}(10/11/2019 )The program must accept an integer N as the input.The program must print the Kth integer in the series given below
19,28,37,46,55,64,73,82,91,109,118 and so on.
Note:The sum of digits in each integer of the above series is exactly 10.
Boundary condition:
1<=K<=1000
EXAMPLE INPUT/OUTPUT 1:
INPUT:
4
OUTPUT
46
Explanation:
The 4th integer in the series is 46(4+6=10).So 46 is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
7
OUTPUT
73
#include<stdio.h>#include<string.h>int main() { int n,count=0; scanf("%d",&n); for(int i=19;i<=100036;i+=9) { int sum=0; int c=i; while(c>0) { sum+=c%10; c/=10; } if(sum%10==0) { count++; } if(count==n) { printf("%d",i); return 0; } } }(09/11/2019 )The program must accept an integer N as the input.The program must from an integer X by removing exactly one digit from N so that X is divisible by 8.The program must print YES if it is possible to form the integer X.Else the program must print No as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
3454
OUTPUT
YES
Explanation:
after removing the tenth digit %,the integer becomes 344.Here ,the integer 344 is divisible by 8.So YES is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
79
OUTPUT
NO
#include<stdio.h>#include<string.h>int main() { char a[1000]; int len; scanf("%s%n",a,&len); while(len>0) { int result=0; for(int i=0;i<strlen(a);i++) { if(i!=len-1) { result=result*10+(a[i]-'0'); } } len--; if(result==0) { printf("NO"); return 0; } if(result%8==0) { printf("YES"); return 0; } } printf("NO");}(08/11/2019 )The program must accept an integer N as the input.The program must print the desired pattern as shown in the Example iInput/Output section
EXAMPLE INPUT/OUTPUT 1:
INPUT:
5
OUTPUT
1
1 2
1 2 3
1 2 2 2
1 1 1 1 1
EXAMPLE INPUT/OUTPUT 2:
INPUT:
10
OUTPUT
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 5
1 2 3 4 4 4 4
1 2 3 3 3 3 3 3
1 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1
#include<stdio.h>int main() { int n,r=1,k=0; int max=0,equ,a=0,count=0; scanf("%d",&n); if(n%2==1) { equ=(n/2)+1; a=1; } else { equ=n/2; } for(int i=1;i<=n;i++) { if(i<=equ) { for(int j=1;j<=r;j++) { printf("%d ",j); } if(i>max) { max=i; } } else { if(a==1 &&count==0) { max=max-1; count=1; } for(int k=1;k<=r;k++) { if(k>=max) { printf("%d ",max); } else { printf("%d ",k); } } max--; } printf("\n"); r++; }}(07/11/2019 )The program must accept an integer N as the input.The program must print the desired pattern as shown in the Example iInput/Output section
EXAMPLE INPUT/OUTPUT 1:
INPUT:
4
OUTPUT
ab
a
abcd
abc
EXAMPLE INPUT/OUTPUT 2:
INPUT:
7
OUTPUT
ab
a
abcd
abc
abcdef
abcde
abcdefgh
#include<stdio.h>int main() { char a[]="abcdefghijklmnopqrstuvwxyz"; int n; scanf("%d",&n); for(int i=1;i<=n;i++) { if(i%2==1) { for(int j=0;j<i+1;j++) { printf("%c",a[j]); } } else { for(int j=0;j<i-1;j++) { printf("%c",a[j]); } } printf("\n"); }}(06/11/2019 )Please convert the following Python code to C so that the C program executes successfully passing all the test cases.
#length of strVal is always less than or equal to 100
#X is always less than Y
strVal=input().strip()
X,Y=[int(val) for val in input().split()]
print(strVal[:X])
print(strVal[X:Y])
print(strVal[-Y:])
#include<stdio.h>#include<string.h>#include<stdlib.h>int main(){ char *a; a=malloc(sizeof(char)); int x,y,len; scanf("%s%n\n",a,&len); scanf("%d %d",&x,&y); for(int i=0;i<=x-1;i++) { printf("%c",a[i]); } printf("\n"); for(int i=x;i<y;i++) { printf("%c",a[i]); } printf("\n"); for(int i=(len-y);i<len;i++) { printf("%c",a[i]); }}(05/11/2019 )The program must accept an integer N as the input.For each digit D in N,the program must print the digit D for X times where X is formed by removing the digit D from the integer N as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
121
OUTPUT
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1
EXPLANATION:
For the first digit in 121,the value of X is 21.so 1 is printed for 21 times.
For the second digit in 121,the value of X is 11.so 1 is printed for 11 times.
For the first digit in 121,the value of X is 12.so 1 is printed for 12 times.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
210
OUTPUT
2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#include<stdio.h>#include<string.h>#include<stdlib.h>int main() { char *D; D=malloc(sizeof(char)); int X=0,len; scanf("%s%n",D,&len); for(int i=0;i<len;i++) { for(int j=0;j<len;j++) { if(j==i) { continue; } else { X=X*10+(D[j]-'0'); } } for(int k=0;k<X;k++) { printf("%c ",D[i]); } X=0; printf("\n"); }}//In the above code i used to get the integer as string because it will eliminate the use of one loop for getting each digits when the input is in form of integer.(04/11/2019 )Please convert the following Python code to C so that the C program executes successfully passing all the test cases.
strval=input().strip()
vowels='aeiou'
consonants='BCDFGHJKLMNPQRSTVWXYZ'
printed=False
for ch in strval:
if(not ch in vowels)and (not ch in consonants):
print(ch,end="")
printed=True
if not printed:
print(-1)
#include<stdio.h>#include<string.h>int main() { char a[100]; int printed=-1; scanf("%s",a); for(int i=0;i<strlen(a);i++) { if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='B'||a[i]=='C'||a[i]=='D'||a[i]=='F'||a[i]=='G'||a[i]=='H'||a[i]=='J'||a[i]=='K'||a[i]=='L'||a[i]=='M'||a[i]=='N'||a[i]=='P'||a[i]=='Q'||a[i]=='R'||a[i]=='S'||a[i]=='T'||a[i]=='V'||a[i]=='W'||a[i]=='X'||a[i]=='Y'||a[i]=='Z') { continue; } else { printf("%c",a[i]); printed=0; } } if(printed==-1) { printf("-1"); }}(03/11/2019 )A boy is currently at the point 0 on a coordinate axis.He jumps by the following rules.The first jump is X units to the right,the second jump is Y units to the left,the third jump is X units to the right and so on.The program must accept three integers X, Y and K as the input.The program must print the position of the boy after jumps as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
5 2 3
OUTPUT
8
EXPLANATION:
Here X=5 ,Y=2 and K=3.
In first jump,the boy jumps 5 units to the right.Now the current position of the boy is 5(0+5).
In second jump,the boy jumps 2 units to the left.Now the current position of the boy is 3(5-2).
In third jump,the boy jumps 5 units to the right.Now the current position of the boy is 8(3+5).
The final position of the boy jumps is 8(after 3 jumps).So 8 is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
100 1 4
OUTPUT
198
#include<stdio.h>#include <stdlib.h>int main(){ long int x,y,k,m; scanf("%lld %lld %lld",&x,&y,&k); m=k/2; if(k%2==1) { printf("%lld",x*(m+1)-y*m); } if(k%2==0) { printf("%lld",x*m-y*m); }}(02/11/2019 )The program must accept a string S(encrypted string) containing only alphabets as the the input.The encryption algorithm is given below.
The program must decrypt the string S and print it as the output.
NOTE:The string S is always a valid encrypted string.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
baabbb
OUTPUT
bab
EXPLANATION:
baabbb can be decrypted as bab. So bab is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
ooopppssss
OUTPUT
oops
#include<stdio.h>#include<string.h>#include<stdlib.h>int main() { char *a; a=malloc(sizeof(char)); int sum=0,k=1; scanf("%s",a); while(sum<strlen(a)) { printf("%c",a[sum]); sum+=k; k++; }}(01/11/2019 )The program must accept a string S containing only lowercase alphabets ,an alphabet CH and an integer X as the input.The program must remove the first X occurrences of the alphabet CH int the string S.Then the program must print the modified string S as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
digitization
i 3
OUTPUT
dgtzation
EXPLANATION:
After removing the first 3 occurrences of i , the string becomes dgtzation.
Hence dgtzation is printed as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
joyfull
y 3
OUTPUT
jofull
#include<stdio.h>#include<stdlib.h>#include<string.h>int main() { char*a,b; a=malloc(sizeof(char)); int c,k=0; scanf("%s\n%c %d",a,&b,&c); for(int i=0;i<strlen(a);i++) { if(a[i]==b && k<c) { k++; continue; } else { printf("%c",a[i]); } }}(31/10/2019 )The program must accept poistive integers N as the input. The program must print the next greater integer which is divisible by 3 and the sum of digits in it is also divisible by 3 as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
22
OUTPUT
24
EXPLANATION:
the next greater integer which is divisible by 3 and the sum of digits in it 6(2+4) is also divisible by 3 is 24. Hence 24 is the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
84
OUTPUT
87
#include<stdio.h>int main() {int n;scanf("%d",&n);n=n+1;while(1){ if(n%3==0) { printf("%d",n); return 0; } else { n++; }}}(30/10/2019 )The program must accept two integers A and B as the input. The program must print the GCD of A! and B! as the output
EXAMPLE INPUT/OUTPUT 1:
INPUT:
4 3
OUTPUT
6
EXAMPLE INPUT/OUTPUT 2:
INPUT:
4 5
OUTPUT
24
#include<stdio.h>#include <stdlib.h>int main(){ long int c=1; int A,B,min; scanf("%d %d",&A,&B); min=A; if(B<min) { min=B; } for(int i=1;i<=min;i++) { c*=i; } printf("%ld",c);}(29/10/2019 )The program must accept N integer as the input. The program remove the trailing zeros for all the N integers.Then the program must print the smallest integer among the N modified integers as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
5
150 2000 50 8800 24
OUTPUT
2
EXAMPLE INPUT/OUTPUT 2:
INPUT:
4
10 19 457 1000000
OUTPUT
1
#include<stdio.h>int main() { int n,a,min; scanf("%d\n",&n); for(int i=0;i<n;i++) { scanf("%d ",&a); while(a%10==0) { a=a/10; } if(i==0) { min=a; } if(a<min) { min=a; } } printf("%d",min);} (28/10/2019 )The program must accept an integer N as the input. The program must the desired pattern as shown in the Example Input/Output section.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
4
OUTPUT
1 2 3 4
1 2 2 3 4
1 2 3 3 3 4
1 2 3 4 4 4 4
EXAMPLE INPUT/OUTPUT 2:
INPUT:
5
OUTPUT
1 2 3 4 5
1 2 2 3 4 5
1 2 3 3 3 4 5
1 2 3 4 4 4 4 5
1 2 3 4 5 5 5 5 5
#include<stdio.h>int main() { int n,i=1; scanf("%d",&n); while(i<=n) { for(int j=1;j<=n;j++) { if(i==j) { for(int k=0;k<i;k++) { printf("%d ",j); } } else printf("%d ",j); } printf("\n"); i++; }}(27/10/2019 )The program must accept a string S containing only lower case alphabets as the input.The program must remove the repeated vowels in the string S.Then the program must print the modified string S as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
conditioner
OUTPUT
cndtner
Explanation:
The vowels o and i are repeated in the given string.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
skillrack
OUTPUT
skillrack
#include<stdio.h>#include<stdlib.h>int main() { char a[10001],b[10001]; long long int len; long long int count=0; long long int k=0; scanf("%s%lln",a,&len); for(int i=0;i<len;i++) { for(int j=0;j<len;j++) { if(i==j) { continue; } if((a[i]=='a'&&a[j]=='a')|| (a[i]=='e'&&a[j]=='e' )||(a[i]=='i'&&a[j]=='i')|| (a[i]=='o'&&a[j]=='o')||(a[i]=='u'&&a[j]=='u')) { count=1; break; } } if(count==0) { b[k++]=a[i]; } count=0; } b[k]='\0'; printf("%s",b);}(26/10/2019 )The program must accept two integer X and Y as the input.The program must print the uncommon factors of X and Y in descending order as the output.If there is no uncommon factor then the program must print '-1' as output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
24 100
OUTPUT
100 50 25 24 20 12 10 8 6 5 3
Explanation:
The factors of 24 are 1,2,3,4,6,8,12,24.
The factors of 100 are 1,2,4,5,10,20,25,50,100.
The uncommon factors are 3,5,6,8,10,12,20,24,25,50,100.So they are printed in descending order as the output.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
36 36
OUTPUT
-1
#include<stdio.h>int main() { int x,y; scanf("%d %d",&x,&y); if(x==y) { printf("-1"); return 0; } int max=(abs(x-y)+(x+y))/2; for(int i=max;i>=2;i--) { if((x%i!=0 && y%i==0)||(x%i==0 && y%i!=0)) { printf("%d ",i); } }}(25/10/2019 )The program must accept a string S as the input.Then the program the desired pattern as shown in the Example section.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
SkillRack
OUTPUT
(S)killRac(k)
S(k)illRa(c)k
Sk(i)llR(a)ck
Ski(l)l(R)ack
Skil(l)Rack
EXAMPLE INPUT/OUTPUT 2:
INPUT:
hide
OUTPUT
(h)id(e)
h(i)(d)e
#include<stdio.h>#include<stdlib.h>int main() { char *S; S=malloc(sizeof(char)); int start,end,len; scanf("%s%n",S,&len); start=0; end=len-1; while(start<=end) { for(int i=0;i<len;i++) { if(i==start || i==end) { printf("(%c)",S[i]); } else { printf("%c",S[i]); } } printf("\n"); start++; end--; }}(24/10/2019 )The program must accept two integer N and K as input. The program must containing all the odd integer from 1 to N followed by all even integer from 1 to N.Then the program must print the K th integer in sequence as the output.
EXAMPLE INPUT/OUTPUT 1:
INPUT:
10 3
OUTPUT
5
Explanation:
N=10,so sequence is 1 3 5 7 9 2 4 6 8 10
third integer in the sequence is 5.
EXAMPLE INPUT/OUTPUT 2:
INPUT:
7 7
OUTPUT
6
#include<stdio.h>#include <stdlib.h>int main(){int N,K,j=0;scanf("%d %d",&N,&K);for(int i=1;i<=N;i=i+2){ j++; if(j==K) { printf("%d",i); return 0; }}for(int i=2;i<=N;i=i+2){ j++; if(j==K) { printf("%d",i); break; }}}