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; }
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.
+ 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");
+ 3
ChaoticDawg Thanks man that was a lot of help ; )
+ 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"
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