You are on page 1of 2

Tutorial No.

4
Roll No.44
4.Decision Making & branching using if, if-else structure
1.Determine whether a given year is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
//Nested if else
if (year % 100 == 0)
{
if (year % 400 == 0)
printf("%d is a Leap Year", year);
else
printf("%d is not a Leap Year", year);
}
else
printf("%d is a Leap Year", year);
}
else
printf("%d is not a Leap Year", year);
return 0;
}

Output :
Enter year:2000
Is a leap Year

2. Write a program to determine whether the string is palindrome .


#include <stdio.h>
#include <string.h>
int main() {
char string1[20];
int i, length;
int flag = 0;

printf("Enter a string: ");


scanf("%s", string1);

length = strlen(string1);

for (i = 0; i < length / 2; i++) {


if (string1[i] != string1[length - i - 1]) {
flag = 1;
break;
}
}

if (flag) {
printf("%s is not a palindrome\n", string1);
} else {
printf("%s is a palindrome\n", string1);
}

return 0;
}

You might also like