[B] Attempt the following:
(a)Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour.
click here for Answer!!!
Answer:
void main()
{
int hour,employee,overtime,overtime_pay;
employee=1;
while (employee<=10)
{
printf("\nEnter the no.of Hrs done by employee %d:",employee);
scanf ("%d",&hour);
if(hour>40)
{
overtime = hour-40;
overtime_pay =12*overtime;
printf ("\nYour overtime pay is:%d\n\n", overtime_pay);
}
else if (hour<=40)
{ printf("\nYou won't get overtime pay.\n\n");
}
employee++;
}
}
(b)Write a program to find the factorial value of any number entered through the keyboard.
click here for Answer!!!
Answer :
void main()
{
int number,factorial,fact;
printf("Enter the number for calculating factorial: ");
scanf ("%d",&number);
fact=number;
factorial=1;
while(fact>=1)
{
factorial=factorial*fact;
fact--;
}
printf("The factorial of entered number is :%d", factorial);
}
(c)Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another.
click here for Answer!!!
void main()
{
int number1,number2,a=1,b=1;
printf("Enter the number1 to raise power on number2 ");
scanf ("%d",&number1);
printf("Enter the number2: ");
scanf ("%d",&number2);
while(a<=number1)//loops exists number1 times.
{
b = number2*b;
a++;
}
printf("number1 raising power on number2 gives %d",b);
}
(d)Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.
click here for Answer!!!
Answer:
void main()
{
int num=0;
while(num<=255)
{
printf("\nascii= %d character = %c",num,num);
num++;
}
}
(e)Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )
click here for Answer!!!
void main()
{
int i,no,r,t=0;
i=1;
while(i<=500)
{
t=0;
no=i;
while(no!=0)
{
r=no%10;
t = t + r*r*r;
no=no/10;
}
if(t==i)
printf("%d\n",i);
i++;
}
}
(f)Write a program for a matchstick game being played between the computer and a user. Your program should ensure that the computer always wins. Rules for the game are as follows: ? There are 21 matchsticks. ? The computer asks the player to pick 1, 2, 3, or 4 matchsticks. ? After the person picks, the computer does its picking. ? Whoever is forced to pick up the last matchstick loses the game.
click here for Answer!!!
void main()
{
int matchstk,com_slt,total=0,count,sel_times=0;
for(matchstk=1;matchstk<=21;matchstk++)
{
if(total==20)
{
printf("only one matchstick is left that you must select.\ \n!!!!! so you loose!!!!");
break;
}
printf("\nenter the no of matchstick to pick from 1 2 3 or 4"); scanf("%d",&count);
if(count==1||count==2||count==3||count==4)
{
}
else
{
printf("please select from 1-4 only.. ");
matchstk=matchstk-1; continue; } com_slt=5-count;
printf("\nyou select %d",count);
printf("\ncomputer select %d",com_slt); total=total+count+com_slt;
matchstk=total;
printf("\ntotal no of matchstk selected =%d ",matchstk); sel_times=sel_times+1;
printf("\n%d times selection completes\n\n\n",sel_times);
}
}
(g)Write a program to enter the numbers till the user wants and at the end it should display the count of positive, negative and zeros entered.
click here for Answer!!!
Answer:
void main()
{
int num,to_neg=0,to_pos=0,to_zero=0;
char another='y';
while(another=='y')//takes user input till user desire
{
printf("\nenter number: ");
scanf("%d",&num);
if(num==0)
to_zero++;
else if(num>0)
to_pos++;
else if(num<0)
to_neg++;
printf("another no y/n");
fflush(stdin);
scanf("%c",&another);
}
printf("\n");
printf("to.-ve=%d to.+ve=%d to.zero=%d",to_neg,to_pos,to_zero);
}
(h)Write a program to find the octal equivalent of the entered number.
click here for Answer!!!
Answer:
void main()
{
int rem,num,total=0,i=1;
printf("Enter any number for octal equivalent: ");
scanf("%d",&num);
while(num!=0)
{
rem=num%8;
total=total+rem*i;
i=i*10;
num=num/8;
}
printf("Octal equivalent is %d",total);
}
(i)Write a program to find the range of a set of numbers. Range is the difference between the smallest and biggest number in the list.
click here for Answer!!!
Answer:
void main()
{
int i,a=2,b=3,c=20,d=5,e=9,great,least,num;
i=1;
while(i<=5)
{
if(i==1)
num=a;
else if(i==2)
num=b;
else if(i==3)
num=c;
else if(i==4)
num=d;
else if(i==5)
num=e;
//for greatest number if(num>=a&&num>=b&&num>=c&&num>=d&&num>=e) //see note 1
{
great=num;
}
if(num<=a&&num<=b&&num<=c&&num<=d&&num<=e)
{
least=num;
}
i++;
}
printf("least number=%d\n greatest number=%d",least,great);
printf("\n Range=%d",great-least);
}
where can i get pdf file of the let us c solution
ReplyDeletehelpful
ReplyDeletemain()
ReplyDelete{
int e=1,op,h;
while(e<=10)
{
printf("\nEnter number of hours an employee has worked:");
scanf("%d",&h);
op=(h-40)*12;
printf("\nOvertime pay is Rs.%d",op);
e++;
}
}
Τhanks for ѕhагing your thoughts about а.
ReplyDeleteRеgards
My web site iphone repair
I'll right away snatch your rss as I can't іn finԁing your
ReplyDeletee-mail subscriptiοn lіnk or e-newslettеr
ѕеrѵice. Do you've any? Kindly permit me recognize in order that I may subscribe. Thanks.
Here is my web site bluehost mail bluehost hosting
very helpful
ReplyDelete#include
ReplyDeleteint main()
{
int num,temp,count=0,arr[10];
printf("Enter the number in decimal");
scanf("%d",&num);
temp=num;
while(temp>8)
{
arr[count]=temp%8;
temp=temp/8;
count++;
}
arr[count]=temp;
while(count>=0)
{
printf("%d",arr[count]);
count--;
}
return 0;
}
/*My thanks in C language*/
ReplyDelete#include
main()
{
int thanks=1;
printf("\nVery helpful for beginners like me.");
thanks=thanks*10;
printf("\n%d X Thanks",thanks);
printf("\nYours Sincerely : Phani Krishnan");
}
/*My thanks in C language*/
ReplyDelete#include
main()
{
int thanks=1;
printf("\nVery helpful for beginners like me.");
thanks=thanks*10;
printf("\n%d X Thanks",thanks);
printf("\nYours Sincerely : Phani Krishnan");
}