Day 1 Placement Training
Day 1 Placement Training
Program:
#include <stdio.h>
#include<math.h>
int main()
{
int a=99;
printf("%c",(char)a);
}
2.
Write a program to get a float value from the user and
display it in the below-mentioned format.
HINT: Use ceil() and floor() functions from the header file.
Sample Input:
54.5
Sample output:
54 // o.value
55 // round up
54 // round down
Program :
#include <stdio.h>
#include<math.h>
int main()
{
float a=54.5;
printf("%d\n",(int)a);
printf("%d\n",(int)ceil(a));
printf("%d\n",(int)floor(a));
}
3.
Each Saturday, The Herald sells 'a' copies of a special
edition newspaper for Rs. b per copy. The cost to him for
printing each newspaper is Rs. c. He pays a fixed cost of
Rs.100 per Saturday for storage, delivery, and so on. He
wants to calculate the profit which it obtains only on
Saturdays. Can you please help him out by writing a
program to compute the profit if a, b, and c are given?
Sample Input:
1000
2
1
Sample output:
900
Program:
#include <stdio.h>
int main()
{
int a,b,c,o1,o2,res=0;
scanf("%d%d%d",&a,&b,&c);
o1=a*b;
o2=a*c;
res=o1-o2-100;
printf("%d",res);
}
4.
Write a program to reverse the 3 digit number.
Sample Input:
456
Sample output:
654
Program:
#include <stdio.h>
int main()
{
int number,reverse=0,rem=0;
scanf("%d",&number);
while(number != 0)
{
int rem = number % 10;
reverse = reverse * 10 + rem;
number = number/10;
}
printf("%d",reverse);
}
4. Pradeep is designing the input interaction for the X-O
game (a.k.a TIC-TAC-TOE). The user identifies the
positions as 1|2|3 4|5|6| 7|8|9. Since the board is a
2-dimensional layout (3x3), Pradeep uses a 2-dimensional
array to store board status and he identifies positions by
row, and column as for first-row elements -(0,0),(0,1),(0,2)
and for second-row elements - (1,0),(1,1),(1,2) and for 3rd
row elements - (2,0),(2,1),(2,2). Help Pradeep to solve the
conversion from user's input (1-9) to (Row, Column)
(0-2),(0-2) respectively.
Note - Indexing for rows and columns is 0-based.
Sample Input:
6
Sample output:
12
Program:
#include <stdio.h>
int main()
int n;
scanf("%d",&n);
int i=(n-1)/3;
int j=(n-1)%3;
printf("%d %d",i,j);
Sample Input:
791
Sample output:
Trendy number
Program:
#include <stdio.h>
int main()
int n,sl;
scanf("%d",&n);
if((n>=100)&&(n<1000))
sl=(n/10)%10;
if(sl%3==0)
printf("Trendy number");
}else
}else
{
printf("Invalid Number");
Sample Input:
5
5
11
Sample output:
yes
Program:
#include <stdio.h>
int main()
int r,c,t;
scanf("%d%d%d",&r,&c,&t);
if(t<=c||(t%c==1)||(t%c==0))
printf("Yes");
}else
printf("No");
}
7. A prime number is divisible only by 1 and itself. You are
given a positive integer. Write an algorithm to find all the
prime numbers from 2 to the given positive number.
Sample Input:
11
Sample output:
2 3 5 7 11
Program:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
int flag=1;
int m=i/2;
for(int j=2;j<=m;j++)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
{
printf("%d ",i);
}
}
}
Input:
Output:
* * * * *
* *
* *
* *
* * * * *
Program:
#include<stdio.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||j==0||i==n-1||j==n-1)
printf("*");
}else
printf(" ");
printf("\n");
}
10.
Function Signature
Assumptions
The length of the array is always greater than 0.
You need to sum only those product IDs which appear exactly
once.
Input Format
The second input is the array arr which contains the product
IDs.
Output Format
Constraints
1 ≤ length ≤ 10000
The product IDs in the array are positive integers within the
integer range.
Example 1
Sample Input 1
8
25479248
Sample Output 1
29
#include <stdio.h>
int sum = 0;
int d = 0;
d = 1;
break;
}
}
if (d==0) {
sum += a[i];
return sum;
int main() {
int n;
scanf("%d", &n);
int a[n];
scanf("%d", &a[i]);
printf("%d", res);
return 0;
11.
Function Signature
Output Format
Constraints
Example 1
Sample Input 1
abcdabc
Sample Output 1
#include <stdio.h>
#include <string.h>
#include <ctype.h>
if (str == NULL)
return -1;
count[str[i] - 'a']++;
int cnt = 0;
if (count[i] > 0)
cnt++;
return cnt;
int main()
char str[1000001];
scanf("%s", str);
printf("%d\n", numberUniqueCharacters(str));
return 0;
Input Format
Output Format
Example 1
Sample Input 1
Sample Output 1
120
#include <stdio.h>
int fact(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
fact*=i;
return fact;
int main()
int n;
scanf("%d",&n);
printf("%d",fact(n));
return 0;
int main()
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
for(int j=0;j<i+1;j++)
printf("*");
printf("\n");
}
Left Angled Triangle:
#include <stdio.h>
int main()
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
printf(" ");
for(int j=0;j<i+1;j++)
printf("*");
}
printf("\n");
}
Triangle:
#include <stdio.h>
int main()
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
for(int j=0;j<n-i-1;j++)
printf(" ");
for(int j=0;j<i+1;j++)
{
printf("* ");
printf("\n");
Input:
Alliance university
Output:
University alliance
/***********************************************************
*******************
Online C Compiler.
Write your code in this editor and press "Run" button to compile and
execute it.
************************************************************
*******************/
#include <stdio.h>
#include<string.h>
// int main()
// {
// char a[100];
// scanf("%[^\n]s",a);
// int l=strlen(a);
// int count=0,consonants=0;
// for(int i=0;i<l;i++)
// {
// char ch=a[i];
//
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'|
|ch=='O'||ch=='U')
// {
// count++;
// }else{
// consonants++;
// }
// }
// printf("%d %d",count,consonants);
// }
// Write a program to find whether the given string is a palindrome or
not without using string library functions.
// example: mam
// int main()
// {
// char a[100],rev[100];
// scanf("%[^\n]s",a);
// int l=0;
// for(int i=0;a[i]!='\0';i++)
// {
// l++;
// }
// // j=5,4,3,2,1 mam
// // k = 1 2 3 4 5 rev[0]=a[2] rev[m ]
// // rev[1]=a[1] rev[m a m]
// int k=0;
// for(int j=l-1;j>=0;j--)
// {
// rev[k]=a[j];
// k++;
// }
// for(int i=0;i<l;i++)
// {
// if(rev[i]!=a[i]) // ankel
// {
// printf("Not a palindrome");
// return 0;
// }
// }
// printf("Palindrome");
// }
// string reverse for the sentence
int main()
char str[100],word[100];
scanf("%[^\n]s",str);
int count=0;
int l=strlen(str);
int i,j=0;
// for(int i=l-1;i>=0;i--)
// {
// {
// word[j++]=" ";
// }else
// {
// word[j++]=str[i];
// }
// }
// printf("%s",word);
for(int i=l-1;i>=0;i--)
word[j++]=" ";
}else
word[j++]=str[i];
}
int k=0,count1=0;
char rev[100];
for(int i=0;word[i]!="\0";i++)
if(word[i]!=" ")
count1++;
for(int y=count1;y>=0;y--)
rev[k++]=word[count1];
printf("%s",rev);