0

Print output after all input in c

The code works fine but i want to print output after n input For eg. n=2 2001 2000 No Yes Not like this : n=2 2001 No 2000 Yes #include <stdio.h> //Compiler version gcc 6.3.0 int main() { int a, n, i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a); if(a%4==0) { if(a%100==0) { if(a%400==0) { printf("Yes\n"); } else { printf("No\n"); } } else { printf("Yes\n"); } } else { printf("No\n"); } } return 0; }

11th May 2020, 1:41 AM
Saaquib Motiwala
5 Réponses
+ 2
Saaquib Motiwala you'll need to use 2 loops. 1st should loop n times to add values to the array. 2nd should loop n times to check each value and output answer.
11th May 2020, 2:38 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
Use logic If ((a%4==0)&&(a%100==0)) { if (a%400==0) Printf("Yes\n"); Else Printf("no\n"); } Else Printf("no\n");
11th May 2020, 1:59 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
ChaoticDawg Thanks man that was a lot of help ; )
11th May 2020, 2:40 AM
Saaquib Motiwala
+ 1
For it to work like your first example, you need to create an int array of n size to hold the years to be input. Create a loop that will loop n times to get each year input and assign its value to the current index of the loop. Then loop over the array and check each year, outputting the answer for each as you go. BTW you don't need to nest your if statements. pseudocode: if year % 400 == 0 || (year % 4 == 0 && year % 400 != 0) print "Yes\n" else print "No\n"
11th May 2020, 2:19 AM
ChaoticDawg
ChaoticDawg - avatar
0
ChaoticDawg #include <stdio.h> //Compiler version gcc 6.3.0 int main() { int a, n, i; scanf("%d",&n); int arr[10]; for(i=0;i<n;i++) { scanf("%d",&arr[i]); if(arr[i]%4==0) { if(arr[i]%100==0) { if(arr[i]%400==0) { printf("Yes\n"); } else { printf("No\n"); } } else { printf("Yes\n"); } } else { printf("No\n"); } } return 0; } I changed it but same problem
11th May 2020, 2:32 AM
Saaquib Motiwala