Q.1: W.A.P. to find out factorial of a given number.
Ans.: #include
#include
void main()
{
int a,b,c;
clrscr();
a=1;
printf(“Find the factorial of:”);
scanf(“%d”,&b);
for(c=b;c>=1;c--)
{
a=a*c;
}
printf(“Factorial of given number is %d”,a);
getch();
}
Q.2: W.A.P. to find out the entered number is even or odd.
Ans.: #include
#include
void main()
{
int a,b;
clrscr();
printf(“Please Enter Any Number: ”);
scanf(“%d”,&a);
b=a%2;
if(b=0);
{
printf(“Entered Number Is Even”);
}
else
{
printf(“Entered Number Is Odd”)
}
getch();
}
Q.3: W.A.P. to print the sum of n natural number.
Ans.: #include
#include
void main()
{
int a,b,c;
clrscr();
a=0;
printf(“Print the sum of natural number up to: ”);
scanf(“%d”,&b);
for(c=b;c>=0;c--)
{
a=a+c;
}
printf(“%d”c);
getch();
}
Q.5.: W.A.P. to print FIBONACI series.
Ans.: #include
#include
void main()
{
int a=0,b=1,c,i;
clrscr();
printf("\n FIBONACCI SERIES: \n");
printf("\n%d\n%d",a,b);
for(i=1;i<=10;i++)
{
c=a+b;
a=b;
b=c;
printf("\n %d",c);
}
getch();
}
Q.6: W.A.P. to check triangle is valid or not.
Ans.: #include
#include
void main()
{
int a,b,c,s;
clrscr();
printf(“Please Enter The Magnitude Of Ist Angle Of Triangle (in degrees)”);
scanf(“%d”,&a);
printf(“Please Enter The Magnitude Of IInd Angle Of Triangle (in degrees)”);
scanf(“%d”,&b);
printf(“Please Enter The Magnitude Of IIIrd Angle Of Triangle (in degrees”);
scanf(“%d”,&c);
s=a+b+s;
if(s<=360)
{
printf(“Triangle is valid”);
}
else
{
printf(“Triangle is not valid”);
}
getch();
}
Q.7: W.A.P. to find out power of given number.
Ans: #include
#include
#include
void main()
{
int a,b,c;
clrscr();
printf("Enter Any Number: ");
scanf("%d",&a);
printf("Calculate Its Power: ");
scanf("%d",&b);
c=pow(a,b);
printf("Power %d of %d is: %d",b,a,c);
getch();
}
Q.8: W.A.P. to print the sum of odd and even numbers between 1-100.
Ans.: #include
#include
void main()
{
int a,b,se,so;
clrscr();
se=0;
so=0;
for(a=2;a<=100;a=a+2)
{
se=se+a;
}
for(b=1;b<=99;b=b+2)
{
so=so+b;
}
printf("Sum of even natural numbers between 1-100 is: %d",se);
printf("Sum of odd natural numbers between 1-100 is:",so);
getch();
}
Q.12: W.A.P. to read a string and print no. of words in a string.
Ans.: #include
#include
#include
void main()
{
char string[90];
int k;
printf("Enter your name: ");
scanf("%d",&string);
printf("Entered String: %d",string);
k=strlen(string);
printf("Entered sting contains %d words",k);
getch();
}

कोई टिप्पणी नहीं:
एक टिप्पणी भेजें