Code #include<stdio.h>
int main(){
int a[10],test,k,n,j,i;
scanf("%d",&test);
for (i=0;i<test;i++){
scanf("%d",a[i]);
}
for(i=0;i<test;i++){
for(j=0;j<a[1];j++){
printf("hello msg\t");
}
}
}
I am trying to create a test cased , like if we put 2 then loop will work twice then whatever we put twice like 5 and 7 , each loop work like 5 times n and 7 times and so on
Probably what you need instead is
Code for(i=0;i<test;i++){
printf("hello msg\t");
}
for(j=0;j<a[1];j++){
printf("hello msg\t");
}
Not sure If i understood your question
Hack the World!
Sep 27, 2018 12:31 AM
(This post was last modified: Sep 27, 2018 12:32 AM by Quality_k1nG.)
(Sep 26, 2018 10:24 PM)0x45 Wrote: Probably what you need instead is
Code for(i=0;i<test;i++){
printf("hello msg\t");
}
for(j=0;j<a[1];j++){
printf("hello msg\t");
}
Not sure If i understood your question
Hey thank you for the reply. what i want is I was doing some problem on hackerearth.com there they given some test cases (suppose input is 2) then I need to go through the 2 input and again loop inside the 2
like this
https://i.imgur.com/W08pxZT.png
Sep 27, 2018 12:39 AM
(This post was last modified: Sep 27, 2018 12:43 AM by walt3r.)
Try this one, actually I couldn't see your screenshot but I think this is the correct answer.
Code #include<stdio.h>
int main(){
int MAX_SIZE_OF_ARRAY = 10;
int a[MAX_SIZE_OF_ARRAY],test,k,n,j,i;
scanf("%d",&test);
for (i=0;i<test;i++){
scanf("%d",a[i]);
}
for(i=0;i<MAX_SIZE_OF_ARRAY;i++){
for(j=0;j<a[i];j++){
printf("hello msg\t");
}
}
}
Maybe this part is better with this:
http://prntscr.com/kz9ieu
DO NOT DEAL WITH THIS MEMBER
Sep 27, 2018 05:37 PM
(This post was last modified: Sep 27, 2018 05:38 PM by Legionhoster.)
Code should be like this:
Code #include<stdio.h>
#include<conio.h>
int main()
{
int value;
int a[value],k,n,j,i;
printf("Enter the Number of times you want to print the lines : ");
scanf("%d", &a[value]);
for(j=0; j<a[value]; j++){
printf("hello msg\t \n");
}
return 0;
}
I hope this helps.
Sep 27, 2018 06:10 PM
(This post was last modified: Sep 27, 2018 06:20 PM by 0xDEAD10CC.)
It would be much better if you showed the dataset rather than your poor paint drawing. Sounds similar to the codejam type of problems.
Code void process_case(FILE *fp)
{
// read N for iteration count ?
// read data
}
int main(void)
{
FILE *fp = stdin;
#if defined (__TEST_MODE__)
fp = fopen("input.dat", "rb");
#endif
int T, t = 1;
fscanf(fp, "%d", &T);
while (T--) { printf("Case #%d: ", t++); process_case(fp); }
#if defined (__TEST_MODE__)
if (fp) fclose(fp);
#endif
return 0;
}
You'd set it up something like this.
(Sep 27, 2018 06:10 PM)0xDEAD10CC Wrote: It would be much better if you showed the dataset rather than your poor paint drawing. Sounds similar to the codejam type of problems.
Code void process_case(FILE *fp)
{
// read N for iteration count ?
// read data
}
int main(void)
{
FILE *fp = stdin;
#if defined (__TEST_MODE__)
fp = fopen("input.dat", "rb");
#endif
int T, t = 1;
fscanf(fp, "%d", &T);
while (T--) { printf("Case #%d: ", t++); process_case(fp); }
#if defined (__TEST_MODE__)
if (fp) fclose(fp);
#endif
return 0;
}
You'd set it up something like this.
through diagram, it would be much easier to follow idk:D anyway thank for helping
|