26. Write a Program to find Factorial of any number (from for loop).
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int i, f=1, n;
printf("Enter any Number:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
f = f*i;
}
printf("Factorial is : %d",f);
getch();
}
_________________________________________________________________________________
27. Accept a Number from user and calculate its factorial (while loop).
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int n,num;
long fact=1;
printf("Enter the Number:");
scanf("%d", &n);
num=n;
if(n<0)
printf("No Factorial of Negative Number\n");
else
{
while(n>1)
}
fact*=n;
n--;
}
printf("Factorial of %d = %1d\n", fact);
}
getch();
}
_________________________________________________________________________________
28. Write a Program to Print the Feboniccy series.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int f=0, s=1, a=0, n,i;
clrscr();
printf("Enter any number:");
scanf("%d", s);
for(i=1; i<=n; i++)
{
a=f+s;
printf("%d",a);
f=s;
s=a;
}
getch();
}
_________________________________________________________________________________
29. Write a Program to check the given year is leap year or not.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int y;
printf("Enter Any Year:");
scanf("%d", &y);
if(y%u == 0)
{
printf("It is Leap Year");
}
else
{
printf("Not a Leap Year");
}
getch();
}
_________________________________________________________________________________
30. Write a Program to find the difference of two date in years months and days. Assume that
the dates are entered in valid range and that the first date falls before the second date.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int d1, d2, d, m1, m2, m, y1, y2, y;
printf("Enter first date (dd/mm/yyyy):");
scanf("%d%d%d", &d1, &m1, &y1);
printf("Enter second date (dd/mm/yyyy):");
scanf("%d%d%d", &d2, &m2, &y2);
if(d2<d1)
{
if(m2 == 3)
{
if(y2%4 == 0 && y2%100 != || y2%400 == 0)
d2 = d2+29;
else
d2 = d2+28;
}
else if(m2 == 5 || m2 == 7 || m2 == 10 || m2 == 12)
d2 = d2+30;
else
d2 = d2+31;
m2 = m2-1;
}
if(m2<m1)
{
y2 = y2-y1;
m2 = m2+12;
}
y=y2-y1;
m=m2-m1;
d=d2-d1;
printf("Difference of the Two dates are:");
printf("%d years %d months %d days\n"); y,m,d);
getch();
}
*********************************************************************************
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int i, f=1, n;
printf("Enter any Number:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
f = f*i;
}
printf("Factorial is : %d",f);
getch();
}
_________________________________________________________________________________
27. Accept a Number from user and calculate its factorial (while loop).
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int n,num;
long fact=1;
printf("Enter the Number:");
scanf("%d", &n);
num=n;
if(n<0)
printf("No Factorial of Negative Number\n");
else
{
while(n>1)
}
fact*=n;
n--;
}
printf("Factorial of %d = %1d\n", fact);
}
getch();
}
_________________________________________________________________________________
28. Write a Program to Print the Feboniccy series.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int f=0, s=1, a=0, n,i;
clrscr();
printf("Enter any number:");
scanf("%d", s);
for(i=1; i<=n; i++)
{
a=f+s;
printf("%d",a);
f=s;
s=a;
}
getch();
}
_________________________________________________________________________________
29. Write a Program to check the given year is leap year or not.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int y;
printf("Enter Any Year:");
scanf("%d", &y);
if(y%u == 0)
{
printf("It is Leap Year");
}
else
{
printf("Not a Leap Year");
}
getch();
}
_________________________________________________________________________________
30. Write a Program to find the difference of two date in years months and days. Assume that
the dates are entered in valid range and that the first date falls before the second date.
Answer :
#include<stdio.h>
#include<conio.h>
Void main()
{
int d1, d2, d, m1, m2, m, y1, y2, y;
printf("Enter first date (dd/mm/yyyy):");
scanf("%d%d%d", &d1, &m1, &y1);
printf("Enter second date (dd/mm/yyyy):");
scanf("%d%d%d", &d2, &m2, &y2);
if(d2<d1)
{
if(m2 == 3)
{
if(y2%4 == 0 && y2%100 != || y2%400 == 0)
d2 = d2+29;
else
d2 = d2+28;
}
else if(m2 == 5 || m2 == 7 || m2 == 10 || m2 == 12)
d2 = d2+30;
else
d2 = d2+31;
m2 = m2-1;
}
if(m2<m1)
{
y2 = y2-y1;
m2 = m2+12;
}
y=y2-y1;
m=m2-m1;
d=d2-d1;
printf("Difference of the Two dates are:");
printf("%d years %d months %d days\n"); y,m,d);
getch();
}
*********************************************************************************
0 comments:
Post a Comment