WAP to find the sum of the reciprocal of a set of integer numbers to be feed from the keyboard . however reciprocal of 0 is not defined and should be ignored...
void main()
{
float i,no,rev,sum;
clrscr();
for(i=1; i<=5;i++)
{
printf("Enter the number");
scanf("%f", &no);
if(no==0)
continue;
else
rev=1/no;
printf("\n%f",rev);
sum=sum+rev;
}
printf("\n\nsum of reciprocal=%f",sum);
getch();
}
WAP to read the age of 10 persons and count the number of person in the age group 50-60 (Use For and Continue Statement)
void main()
{
int i,age,c=0;
clrscr();
for(i=1; i<=10; i++)
{
printf("Enter the age of the person");
scanf("%d", &age);
if(age>50 && age<60)
{
c++;
continue;
}
}
printf(" %d",c);
getch();
}
WAP to evaluate sqyare root of a series of a numbers and print the result. if number is negative, program should print a message and keeps on counting number of negative values entered by the user......
#include<math.h>
void main()
{
int no,i,c=0,d;
clrscr();
for(i=1; i<=4; i++)
{
printf("Enter the number");
scanf("%d", &no);
if(no<0)
{
printf("\nNo. is negative");
c++;
continue;
}
else
{
d=sqrt(no);
printf("\nsqroot=%d", d);
}
printf("\nNegative numbers= %d",c);
}
getch();
}
WAP in which a loop is initialized by 1 and stops at 100. it will continue the loop when variable of loop is.....
- Less then or equal to 10
- less then 10
- equal to 10
- greater then 10
- greater then or equal to 10
what did you observe????
void main()
{
int i;
clrscr();
for(i=1; i<=100; i++);
{
if(i<=100)
{
continue;
printf("%d",i);
}
}
getch();
}
WAP to read a value a and Calculate value of X for the Given Condition
// conditions are
// if(a>4) then x=a+8
// else x=a+5
void main()
{
int a,x;
clrscr();
printf("Enter the value of a");
scanf("%d",&a);
x=(a>4)? a+8:a+5;
printf(" %d",x);
getch();
}
// if(a>4) then x=a+8
// else x=a+5
void main()
{
int a,x;
clrscr();
printf("Enter the value of a");
scanf("%d",&a);
x=(a>4)? a+8:a+5;
printf(" %d",x);
getch();
}
WAP that determines whether someone is legally an adult (age>=21), but not a senior citizen (age>=65)
void main()
{
int age;
clrscr();
printf("Enter the age");
scanf("%d", &age);
(age>=21 && age<=65)?
printf("\n\nThe person is adult"):printf("\n\nThe person is not adult"):printf("\n\nThe person is not a senior citizen");
getch();
}
Given a point (x,y) WAP to find out it lies on the x-axis, y-axis or at the origin(0,0)
See Othere question This will give in another question or section
WAP by using conditional operator to determine whether a year entered through the keyboard is a leap century year or not
void main()
{
int year;
clrscr();
printf("Enter any year");
scanf("%d", &year);
(year%4==0)?
printf("\n\nIt is a leap year"):printf("\n\nIt is not a leap year");
getch();
}
WAP to check Whether a character entered through the keyboard is a special symbol or not
void main()
{
char no;
clrscr();
printf("Enter the number");
scanf("%c", &no);
(no>=0 && no<=47 || no>=58 && no<=64 || no>=91 && no<=96 || no>=123 && no<=255)?
printf("\n\nIt is a special symbol"):printf("\n\nIt is not a special symbol");
getch();
}
WAP to check whether the character entered through the keyboard is a lower case alphabet or not
void main()
{
char no;
clrscr();
printf("Enter the number");
scanf("%c", &no);
(no>=97 && no<=122)?
printf("\n\nIt is a lower case alphabet"):printf("\n\nIt is not a lower case alphabet");
getch();
}
WAP to check whether a given number is prime or not
void main()
{
int no,i;
clrscr();
printf("Enter the no");
scanf("%d",&no);
for(i=2; i<=no; i++)
{
if(no%i==0)
break;
}
if(no==i)
{
printf("prime");
}
else
{
printf("not prime");
}
getch();
}
WAP To Print prime numbers between 1 to 100
void main()
{
int i,j;
clrscr();
for(i=1; i<=100; i++)
{
for(j=2;j<=i;j++)
{
if(i%j==0)
break;
}
if(i==j)
printf("%d ",i);
}
getch();
}
WAP To Break A Loop At 10th Position When It is executed From 1 to 15
void main()
{
int i;
clrscr();
for(i=1; i<=15; i++)
{
if(i==10)
break;
printf("%d",i);
}
getch();
}
WAP To Calculate a power b by using pow() function
#include<math.h>
void main()
{
int a,b,power;
clrscr();
printf("Enter the value of a and b");
scanf("%d%d",&a,&b);
power=pow(a,b);
printf("%d",power);
getch();
}
WAP to exit from program. through exit(0) function
#include<math.h>
void main()
{
int a,b;
clrscr();
if (a>b)
printf("a is greater");
else
exit(0);
getch();
}
WAP to calculate random value for given number
#include<stdlib.h>
void main()
{
int a;
clrscr();
randomize();
printf("%d",random(50));
getch();
}
WAP to calculate Square root of a given number
#include<math.h>
void main()
{
int a,d;
clrscr();
printf("Enter the value of a");
scanf("%d",&a);
d=sqrt(a);
printf("%d",d);
getch();
}
WAP to calculate cos,acos,sin,asin,tan,Exponential & Log value
#include<math.h>
void main()
{
double a,c,s,as,t,e,l;
clrscr();
printf("Enter the value of a");
scanf("%lf",&a);
c=sin(a*3.14/180);
printf(" \nlf",c);
s=cos(a*3.14/180);
printf("\n%lf",s);
as=asin(a);
printf("\n%lf",as);
t=tan(a);
printf("\n%lf",t);
e=exp(a);
printf("\n%lf",e);
l=log(a);
printf("\n%lf",l);
getch();
}
Subscribe to:
Posts (Atom)