C Program to Multiply given Number by 4 using Bitwise Operators
#include
#include
void main()
{
long number, tempnum;
clrscr();
printf("Enter an integer \n");
scanf("%ld", &number);
tempnum = number;
number = number << 2;
printf("%ld x 4 = %ld\n", tempnum, number);
getch();
}
Output
Enter an integer
450
450 x 4 = 1800
C Program to Find the Sum of first 50 Natural Numbers using for Loop
#include
#include
void main()
{
int num, sum = 0;
for (num = 1; num <= 50; num++)
{
sum = sum + num;
}
printf("Sum = %4d\n", sum);
getch();
}
Output
Sum = 1275
C Program to accept two Integers and Check if they are Equal
#include
#include
void main()
{
int m, n;
clrscr();
printf("Enter the values for M and N\n");
scanf("%d %d", &m, &n);
if (m == n)
printf("M and N are equal\n");
else
printf("M and N are not equal\n");
getch();
}
Output
Enter the values for M and N
3 3
M and N are equal
C Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average
#include
#include
void main()
{
float height;
clrscr();
printf("Enter the Height (in centimetres) \n");
scanf("%f", &height);
if (height < 150.0)
printf("Dwarf \n");
else if ((height >= 150.0) && (height <= 165.0))
printf(" Average Height \n");
else if ((height >= 165.0) && (height <= 195.0))
printf("Taller \n");
else
printf("Abnormal height \n");
getch();
}
Output
Enter the Height (in centimetres)
190
Taller
C Program to Read a Grade & Display the Equivalent Description
#include
#include
#include
#include
void main()
{
char remark[15];
char grade;
printf("Enter the grade \n");
scanf("%c", &grade);
grade = toupper(grade);
switch(grade)
{
case 's':
strcpy(remark, " Super");
break;
case 'a':
strcpy(remark, " Very good");
break;
case 'b':
strcpy(remark, " Fair");
break;
case 'y':
strcpy(remark, " Absent");
break;
case 'f':
strcpy(remark, " Fails");
break;
default :
strcpy(remark, "Error in grade \n");
break;
}
printf("Result : %s\n", remark);
getch();
}
Output
Enter the grade
s
Result: Super
C Program to Compute the Sum of Digits in a given Integer
#include
#include
void main()
{
long num, temp, digit, sum = 0;
printf("Enter the number \n");
scanf("%ld", &num);
temp = num;
while (num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}
printf("Given number = %ld\n", temp);
printf("Sum of the digits %ld = %ld\n", temp, sum);
getch();
}
Output
Enter the number
300
Given number = 300
Sum of the digits 300 = 3
No comments:
Post a Comment