CTS Coding Questions With Answers
CTS Coding Questions With Answers
CTS Programming
Questions with Answers
CTS Programming Test Questions are not like a general Coding Round Questions with
Solutions it is all together different from C programming. We have analysed over 100+
CTS Programming Questions. Below you will find CTS Programming Round Questions,
CTS Coding Questions that are asked constantly in CTS Placement test. The
languages that you can use in the test are –
C
C++
Java
Python
Perl
If you’re looking for CTS Programming Logic questions visit this page.
Subscribe on YouTube
Subscribe
Important Note
No Of Questions:- 1 Question
Time - 30 mins (Some websites say 20 mins, which is incorrect)
Get all the questions asked Today in CTS here -
or
Free Materials
1. Checking if a given year is leap year or not
Explanation:
To check whether a year is leap or not
Step 1:
We first divide the year by 4.
If it is not divisible by 4 then it is not a leap year.
If it is divisible by 4 leaving remainder 0
Step 2:
Step 3:
C
C++
Java
Python
Perl
#include<stdio.h>
int leapprog(int year)
{
//checking divisibility by 4
if(year%4 == 0)
{
//checking divisibility by 100
if( year%100 == 0)
{
//checking divisibility by 400
if ( year%400 == 0)
printf("%d, the year entered happens to be a leap year", year);
else
printf("%d is surely not a leap year", year);
}
else
printf("%d, the year entered happens to be a leap year", year );
}
else
printf("%d is surely not a leap year", year);
return 0;
}
int main()
{
int input_year, val;
printf("Enter the year that you want to check"); //enter the year to check
scanf("%d",&input_year);
val = leapprog(input_year);
return 0;
}
It is positive then call the function prime and check whether the take
positive number is prime or not.
C
C++
Java
Python
Perl
#include<stdio.h>
void prime(int n)
{
int c=0;
for(int i=2;i<n;i++)
{
if(n%i==0)
c = c+1;
}
if(c>=1)
printf("%d is not a prime number",n);
else
printf("%d is a prime number",n);
}
void main()
{
int n;
printf("Enter no : "); //enter the number
scanf("%d",&n);
if(n<0)
{
printf("Please enter a positive integer");
}
else
prime(n);
}
C
C++
Java
Python
Perl
#include<stdio.h>
int main()
{
int i, n, a=0, b=0;
printf("enter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
a = a + 7;
}
else
{
b = b + 6;
}
}
if(n%2!=0)
{
printf("%d term of series is %d\t",n,a-7);
}
else
{
printf("%d term of series is %d\t",n,b-6);
}
return 0;
}
C
C++
Java
Python
Perl
#include<stdio.h>
int main()
{
int i, n, a=1, b=1;
printf("enter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
a = a * 2;
}
else
{
b = b * 3;
}
}
if(n%2!=0)
{
printf("\n%d term of series is %d\t",n,a/2);
}
else
{
printf("\n%d term of series is %d\t",n,b/3);
}
return 0;
}
C
C++
Java
Python
#include<stdio.h>
int main()
{
int i, n, a=0, b=0;
printf("enter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
if(i>1)
a = a + 2;
}
else
{
b = a/2;
}
}
if(n%2!=0)
{
printf("%d",a);
}
else
{
printf("%d",b);
}
}
or
#include<stdio.h>
int main()
{
int i, n, a=0, b=0;
printf("enter number : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
a = a + 2;
}
else
{
b = b + 1;
}
}
if(n%2!=0)
{
printf("%d",a-2);
}
else
{
printf("%d",b-1);
}
}
1. These three words will be read one at a time, in three separate line
2. The first word should be changed like all vowels should be replaced by %
3. The second word should be changed like all consonants should be replaced by #
4. The third word should be changed like all char should be converted to upper
case
5. Then concatenate the three words and print them
Other than these concatenated word, no other characters/string should or message should be
written to STDOUT
For example if you print how are you then output should be h%wa#eYOU.
You can assume that input of each word will not exceed more than 5 chars
(asked in CTS NQT September 3, 2018 Slot 1)
C
C++
Java
#include
#include
int main()
{
char a[10], b[10], c[10];
int i,j;
int x, y, z;
gets(a);
gets(b);
gets(c);
x = strlen(a);
y = strlen(b);
for(i=0;i<x;i++)
{
if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')
{
a[i] = '%';
}
}
for(j=0;j<y;j++)
{
if(b[j]=='b'||b[j]=='c'||b[j]=='d'||b[j]=='f'||b[j]=='g'||b[j]=='h'||
b[j]=='j'||b[j]=='k'||b[j]=='l'||
b[j]=='m'||b[j]=='n'||b[j]=='p'||b[j]=='q'||b[j]=='r'||b[j]=='s'||
b[j]=='t'||b[j]=='v'||b[j]=='w'||
b[j]=='x'||b[j]=='y'||b[j]=='z')
{
b[j] = '#';
}
}
z=0;
while (c[z] != '\0') {
if (c[z] >= 'a' && c[z] <= 'z')
{
c[z] = c[z] - 32;
}
z++;
}
printf("%s %s %s",&a,&b,&c);
}
C
C++
Java
#include<stdio.h>
addition(int x, float y)
{
float ans;
ans = (float)x + y;
printf("Answer : %.2f",ans);
}
int main()
{
int a;
float b;
printf("enter first number : ");
scanf("%d",&a);
printf("enter second number : ");
scanf("%f",&b);
addition(a, b);
}
C
Code:
#include<stdio.h>
int main() {
//code
int n;
scanf(“%d”, &n);
if(n % 2 == 1)
{
int a = 1;
int r = 2;
int term_in_series = (n+1)/2;
int res = 2 * (term_in_series – 1);
printf(“%d “, res);
}
else
{
int a = 1;
int r = 3;
int term_in_series = n/2;
return 0;
}
Online Classes
Question 0
Find the nth term of the series.
1,1,2,3,4,9,8,27,16,81,32,243,….
#include<stdio.h>
#include<math.h>
int three(n)
int x,i;
for(i=0;i<100;i++)
x=pow(3,i);
if(i==n)
printf("%d",x);
}
}
int two(n)
int x,i;
for(i=0;i<100;i++)
x=pow(2,i);
if(i==n)
printf("%d",x);
int main()
int n;
scanf("%d",&n);
if(n%2==0)
three(n/2);
else
two(n/2+1);