Question 1:
Write a program that prints the word addition as "MANIT" using the ASCII value of individual characters.
Code
#include <stdio.h>
int main() {
char a='M', b='A', c='N',d='I',e='T';
int sum;
sum = a+b+c+d+e;
printf("Sum of %c+%c+%c+%c+%c is
%d"
,a,b,c,d,e,sum);
}
Output:
Sum of M+A+N+I+T is 377
Question 2:
Write a program to find
MIN and MAX without using IF-ELSE and take three values from the
user.
Code
#include <stdio.h>
main()
{
int a, b, c, Max, Min ;
printf("Enter three numbers : ")
;
scanf("%d %d %d", &a, &b,
&c) ;
Max = a > b ? (a > c ? a : c) : (b
> c ? b : c) ;
Min = a < b ? (a < c ? a : c) : (b
< c ? b : c) ;
printf("\nThe Biggest number is : %d
\nThe Smallest number is : %d", Max, Min) ;
}
Output:
Enter three numbers : 45
87
12
The Biggest number is : 87
The Smallest number is :
12
Question 3:
Write a program to
calculate profit or loss; where take input cost
price and selling price.
Code
#include <stdio.h>
int main()
{
int cp,sp, amt;
printf("Enter cost price: ");
scanf("%d", &cp);
printf("Enter selling price: ");
scanf("%d", &sp);
if(sp > cp)
{
amt = sp - cp;
printf("Profit = %d", amt);
}
else if(cp > sp)
{
amt = cp - sp;
printf("Loss = %d", amt);
}
else
{
printf("No Profit No Loss.");
}
return 0;
}
Output:
Enter cost price: 1589
Enter selling price: 1200
Loss = 389
Question 4:
Write a programme to left
shift by two bits of any number and also check the number dividing by 4 or not.
Code
#include <stdio.h>
main()
{
long number, after_number;
printf("Enter an integer \n");
scanf("%d", &number);
after_number = number << 2;
printf("before Shift : %d \nAfter
Shift : %d", number, after_number);
if(after_number%4==0)
printf("\nYes,
Its Divisible by 4");
else
printf("\nNo, Its notDivisible by
4");
}
Output:
Enter an integer
123
before Shift : 123
After Shift : 492
Yes, Its Divisible by 4
Comments
Post a Comment