I was participating in some coding contests and luckily my code also ran. However my solution was not expected because i was wrong with the pattern of taking input.
The question involved taking in an integer as an input and performing some operation and returning a different or same integer. I do not have any problem with the program, I just don’t know how to code so as to take inputs like this
Input
The input will contain several test cases (not more than 10).
Each test case is a single line with a number n, 0 <= n <= 1 000 000 000.
It is the number given as input.
Output
For each test case output a single line, containing the integer returned.
Example
Input:
12
2
Output:
13
2
My code is
#include <stdio.h>
int functionReturningInteger(int n)
{
// implementation
........
return num;
}
int main(void)
{
int number;
//printf("Enter the number: ");
scanf("%d",&number);
printf(functionReturningInteger(number));
return 0;
}
How am i supposed to know how many inputs they will give ( although they do provide a maximum limit). And if i use an array to store these inputs whose size is equal to the maximum limit, how do i check the size of an integer array in c ?
I will appreciate anybody helping out with a small piece of code. Also if am able to test it against an input test file and generate an “output.txt” (output file). I already have the desired output file “des.txt”. Then how can i match whether both the files are same or not ?
If
scanfdetects the end of input before a successful conversion, it returnsEOF.For the other questions, redirect input and output,
and compare