Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1 .

THE GIVEN NUMBER IS LEAP OR NOT LEAP YEAR:


#include <stdio.h>

int main()

int y;

printf("Enter year: ");

scanf("%d",&y);

if(y % 4 == 0)

//Nested if else

if( y % 100 == 0)

if ( y % 400 == 0)

printf("%d is a Leap Year", y);

else

printf("%d is not a Leap Year", y);

else

printf("%d is a Leap Year", y );

else

printf("%d is not a Leap Year", y);

return 0;

OUTPUT:
Enter year: 1996

1996 is a Leap Year

2 .CHECK THE GIVEN NUMBER IS ODD OR EVEN:

#include <stdio.h>

int main()

int n;

printf("enter the value:");

scanf("%d",&n);

if(n%2==0)

printf("%d is even",n);

else

printf("%d is odd",n);

return 0;

OUTPUT:

enter the value:11


11 is odd
3 .CALCULATE THE SUM OF ODD & EVEN NUMBERS:

#include <stdio.h>

void main()

int i, num, odd_sum = 0, even_sum = 0;

printf("Enter the value of num\n");

scanf("%d", &num);

for (i = 1; i <= num; i++)

if (i % 2 == 0)

even_sum = even_sum + i;

else

odd_sum = odd_sum + i;

printf("Sum of all odd numbers = %d\n", odd_sum);

printf("Sum of all even numbers = %d\n", even_sum);

OUTPUT:

Enter the value of num

20

Sum of all odd numbers = 100

Sum of all even numbers = 110


4 .CHECK THE GIVEN NUMBER IS POSITVE OR NOT:

#include <stdio.h>

int main()

int n;

printf("enter the value");

scanf("%d",&n);

if(n>=0)

printf("%d is positive",n);

else

printf("%d is negative",n);

return 0;

OUTPUT 1:

enter the value23


23 is positive
OUTPUT 2:

enter the value-25


-25 is negative
5 .FIND THE NUMBER OF INTIGER DIVISABLE BY 5:

#include <stdio.h>

int main()

int n,i,count=0;

printf("enter the value");

scanf("%d",&n);

for(i=1;i<=n;i++)

if(i%5==0)

count=count+1;

printf("%d",i);

printf("count=%d",count);

return 0;

OUTPUT:

enter the value15


51015count=3

You might also like