CTS Coding Questions
CTS Coding Questions
CTS Coding Questions
1. #include<stdio.h>
int main()
int l;
scanf("%d",&l);
double lt=(l*1.00);
if(lt<1)
printf("invalid input");
exit(0);
int d;
scanf("%d",&d);
double dt=(d*1.00);
if(dt<1)
printf("invalid input");
exit(0);
double lk=(lt/dt)*100;
printf("liters/100 km :");
printf("%.2f\n",lk);
double z=dt*0.6214;
double x=lt*0.2642;
double y=(z/x);
printf("miles/gallons :");
printf("%.2f",y);
}
2. #include<stdio.h>
int main()
int p;
scanf("%d",&p);
int pu;
scanf("%d",&pu);
int c;
scanf("%d",&c);
3. #include<stdio.h>
int main()
int n1,n2,n3,n4;
scanf("%d %d %d %d",&n1,&n2,&n3,&n4);
printf("%d - %c\n",n1,n1);
printf("%d - %c\n",n2,n2);
printf("%d - %c\n",n3,n3);
printf("%d - %c\n",n4,n4);
}
4. #include<stdio.h>
int main()
int d;
scanf("%d",&d);
switch(d)
case 12:
case 1:
case 2:
printf("Season : Winter");
break;
case 4:
case 5:
case 6:
printf("Season : Spring");
break;
case 7:
case 8:
case 9:
printf("Season : Summer");
break;
case 10:
case 11:
printf("Season : Autumn");
break;
default:
printf("invalid month");
}
5. #include<stdio.h>
int main()
int n;
scanf("%d",&n);
if(n==0)
printf("no factors");
else if(n>0)
for(int i=1;i<=n;i++)
if(n%i==0)
printf("%d ",i);
else if(n<0)
n=n*-1;
for(int i=1;i<=n;i++)
if(n%i==0)
printf(",%d",i);
}
6. #include<stdio.h>
int main()
int n,sum=0,r;
scanf("%d",&n);
int temp=n;
while(n>0)
r=n%10;
sum=sum*10+r;
n/=10;
if(temp==sum)
printf("yes");
else
printf("no");
7. #include<stdio.h>
int main()
int c;
scanf("%d",&c);
int m;
scanf("%d",&m);
int e;
scanf("%d",&e);
printf("Invalid input");
else if(c==m && m==e && e==c)
printf("CSC\n");
printf("MECH");
printf("MECH\n");
printf("ECE");
printf("ECE\n");
printf("CSC");
printf("CSC");
printf("MECH");
else
{
printf("ECE");
8. #include<stdio.h>
int main()
float s;
scanf("%f",&s);
float p;
scanf("%f",&p);
printf("Invalid input");
s=s+s/100*10;
printf("%.2f",s);
s=s+s/100*25;
printf("%.2f",s);
s=s+s/100*30;
printf("%.2f",s);
}}
9. #include<stdio.h>
int main()
int n,m,sum=0;
scanf("%d",&n);
if(n<1000 || n>9999)
printf("invalid number");
else
while(n!=0)
m=n%10;
sum+=m;
n/=10;
printf("Lucky number");
else
10.