0% found this document useful (0 votes)
44 views

Write A C Program To Check Whether The Input Year Is Leap Year or Not

The document contains C code for several programs: 1) A program to check if a year is a leap year or not 2) A program to calculate the sum of the first n natural numbers 3) A program to print a half pyramid of increasing letters 4) A program to print a decreasing number pattern 5) A program to reverse a number 6) A program to print the Fibonacci series up to a given number

Uploaded by

aaa
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Write A C Program To Check Whether The Input Year Is Leap Year or Not

The document contains C code for several programs: 1) A program to check if a year is a leap year or not 2) A program to calculate the sum of the first n natural numbers 3) A program to print a half pyramid of increasing letters 4) A program to print a decreasing number pattern 5) A program to reverse a number 6) A program to print the Fibonacci series up to a given number

Uploaded by

aaa
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Write a C program to check whether the

input year is leap year or not.


#include<stdio.h>
#include<conio.h>
void main()
{
int year;
printf(“Enter the Year \n:”);
scanf(“%d”,&year);
if(year%4==0 && year%100!=0 || year%400==0)
printf(“\n Leap Year”);
else
printf(“\n Not a Leap Year”);
getch();
}
Write a C program to find out addition of first n
natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
printf(“Enter the value of n \n:”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
//printf(“ %d +”,i);
sum=sum + i;
}
printf(“sum = %d”,sum);
getch();
}
Program to print half pyramid using alphabets

A
BB
CCC
DDDD
EEEEE
#include <stdio.h>
void main()
{
int i, j,n;
char alphabet = 'A';
printf("Enter the uppercase character you want to print in last row: ");
scanf("%c",&n);
for(i=1; i <=n; i ++)
{
for(j=1;j<=i; j++)
{
printf("%c", alphabet);
}
alphabet++;
printf("\n");
}
getch();
}
Write Program to print the following Pattern.

12345
2345
345
45
5
#include <stdio.h>
void main()
{
int i, j,k;
for(i=1; i <=5; i++)
{
for(k=1;k<i; k++)
printf(“ “);
for(j=i;j<=5; j++)
{
printf("%d", j);
}
printf("\n");
}
getch();
}
C Program to reverse a number.
#include <stdio.h>
void main()
{
int n, rev = 0, rem;
printf("Enter an integer: ");
scanf("%d", &n);
while(n != 0)
{
rem = n%10;
rev = rev*10 + rem;
n /= 10;
}
printf("Reversed Number = %d", rev);
getch();
}
Write a C program which prints Fibonacci series.
#include <stdio.h>
void main()
{
int n, a=1,b=1,c;
printf("Enter Last number: ");
scanf("%d", &n);
printf(“\n Fibonacci Series:\t %d \t %d”,a,b);
do
{
c = a+b;
printf(“\t %d”,c);
a=b;
b=c;
} while(c <= n);
getch();
}

You might also like