0
related to test cases
when test case is given, how to print anwsers of all test cases together at the end of the program in output? #include <stdio.h> #include <conio.h> int main() { int t,i; scanf("%d",&t); int a,b,R[t]; while(t!=0) { scanf("%d %d",&a,&b); int r=a%b; R[t]=r; t--; } for(i=0;i<t;i++) { printf("%d\n",R[i]); } return 0; }
4 Antworten
+ 2
Mahima Desani
No need to print answer of all test cases. You just have to write a logic which will print output whatever we provide input.
+ 2
Ok ... thanks
0
But I want output after all input are taken from user
for example
for find remainder
test case =2
1 2
40 15
so, I want out of both test case after insertion of both input.
output :
1
10
like this...
0
Your code has two problems:
conio.h is unavailable and not needed anyway it seems
You have to keep t for output loop to work, but you are decreasing it to 0 before. Use i in first loop instead
#include <stdio.h>
int main()
{
int t,i;
scanf("%d",&t);
int a,b,R[t];
for(i=0;i<t;i++)
{
scanf("%d %d",&a,&b);
int r=a%b;
R[i]=r;
}
for(i=0;i<t;i++)
{
printf("%d\n",R[i]);
}
return 0;
}