C Practice Questions
C Practice Questions
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
OUTPUT
Hello World!
#include<stdio.h>
int main()
{
int a,b,sub;
printf("Enter the first no.: ");
scanf("%d",&a);
printf("Enter the second no.: ");
scanf("%d",&b);
sub= a-b;
printf("subtract is = %d\n", sub);
return 0;
}
OUTPUT
Enter the first no.: 12
Enter the second no.: 6
subtract is = 6
#include <stdio.h>
int main()
{
int a,b,sum;
float avg;
printf("Enter first number :");
scanf("%d",&a);
printf("Enter second number :");
scanf("%d",&b);
sum=a+b;
avg= (float)(a+b)/2;
return 0;
}
OUTPUT
Enter first number :20
Enter second number :35
Sum of 20 and 35 is = 55
Average of 20 and 35 is = 27.500000
#include <stdio.h>
int main()
{
char ch;
//input character
printf("Enter the character: ");
scanf("%c",&ch);
OUTPUT
Enter the character: A
ASCII is = 65
5.C program to find cube of an integer number using two different methods
#include <stdio.h>
int main()
{
int a,cube;
printf("Enter any integer number: ");
scanf("%d",&a);
//calculating cube
cube = (a*a*a);
printf("CUBE is: %d\n",cube);
return 0;
}
OUTPUT
Enter any integer number: 3
CUBE is: 27
#include <stdio.h>
int main()
{
int dividend, divisor;
int quotient, remainder;
printf("Enter dividend: ");
scanf("%d",÷nd);
printf("Enter divisor: ");
scanf("%d",&divisor);
quotient= dividend/divisor;
remainder= dividend%divisor;
return 0;
}
OUTPUT
Enter dividend: 48
Enter divisor: 2
quotient: 24, remainder: 0
#include <stdio.h>
int main()
{
float amount,rate,time,si;
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int num;
return 0;
}
OUTPUT
Enter an integer number: 45
45 is an ODD number.
int main()
{
int a,b,c;
int largest;
return 0;
}
OUTPUT
Enter three numbers (separated by space):23
245
367
Largest number is = 367
#include<stdio.h>
int main()
{
int a ;
//input age
printf("Enter the age of the person: ");
scanf("%d",&a);
return 0;
}
OUTPUT
Enter the age of the person: 23
Eigibal for voting
#include<stdio.h>
int main()
{
int science;
int math;
int english;
int total;
float per;
science = 50;
math = 90;
english = 40;
//you can take input from user instead of these values
//calculating total
total= science + math + english;
//calculating percentage
per= (float) total*100/300;
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
char name[30];
float basic, hra, da, pf, gross;
printf("Enter name: ");
gets(name);
printf("Enter Basic Salary: ");
scanf("%f",&basic);
printf("Enter HRA: ");
scanf("%f",&hra);
printf("Enter D.A.: ");
scanf("%f",&da);
pf= (basic*12)/100;
gross=basic+da+hra+pf;
return 0;
}
OUTPUT
Enter name: Mike
Enter Basic Salary: 23000
Enter HRA: 9500
Enter D.A.: 9500
13. C program to convert temperature from Fahrenheit to Celsius and vice versa
float fh,cl;
int choice;
#include <stdio.h>
#include <math.h>
int main()
{
int x,n;
int result;
result =pow((double)x,n);
OUTPUT
Enter the value of base: 3
Enter the value of power: 7
3 to the power of 7 is= 2187
#include <stdio.h>
int main()
{
int a,b;
int diff;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
if( a>b )
diff=a-b;
else
diff=b-a;
OUTPUT
Enter first number: 34
Enter second number: 21
Difference between 34 and 21 is = 13
16. C program to print size of variables using sizeof() operator
#include <stdio.h>
int main()
{
int a,b;
int diff;
OUTPUT
Enter first number: 48
Enter second number: 14
Difference between 48 and 14 is = 34
#include <stdio.h>
int main()
{
printf("Hello\nWorld!"); //use of \n
printf("\nHello\tWorld!"); // use of \t
printf("\nHello\bWorld!"); //use of \b
return 0;
}
OUTPUT
Hello
World!
Hello World!
"Hello World!"
Hello#World!
#include <stdio.h>
#define PI 3.14f
int main()
{
float rad,area, perm;
printf("Enter radius of circle: ");
scanf("%f",&rad);
area=PI*rad*rad;
perm=2*PI*rad;
printf("Area of circle: %f \nPerimeter of circle: %f\n",area,perm);
return 0;
}
OUTPUT
Enter radius of circle: 4
Area of circle: 50.240002
Perimeter of circle: 25.120001
#include <stdio.h>
int main()
{
float l,b,area;
printf("Enter the value of length: ");
scanf("%f",&l);
printf("Enter the value of breadth: ");
scanf("%f",&b);
area=l*b;
printf("Area of rectangle: %f\n",area);
return 0;
}
OUTPUT
Enter the value of length: 3
Enter the value of breadth: 4
Area of rectangle: 12.000000
20. C program to calculate HCF of two numbers
#include <stdio.h>
int findHcf(int a,int b)
{
int temp;
if(a==0 || b==0)
return 0;
while(b!=0)
{
temp = a%b;
a = b;
b = temp;
}
return a;
}
int main()
{
int a,b;
int hcf;
hcf=findHcf(a,b);
printf("HCF (Highest Common Factor) of %d,%d is: %d\n",a,b,hcf);
return 0;
}
OUTPUT
Enter first number: 234
Enter second number: 34
HCF (Highest Common Factor) of 234,34 is: 2
#include <stdio.h>
int main()
{
int a,b;
int mul,loop;
mul=0;
for(loop=1;loop<=b;loop++){
mul += a;
}
return 0;
}
OUTPUT
Enter first number: 12
Enter second number: 17
Multiplication of 12 and 17 is: 204
#include <stdio.h>
int a=10; //global variable
void fun(void);
int main()
{
int a=20; /*local to main*/
int b=30; /*local to main*/
void fun(void)
{
int b=40; /*local to fun*/
OUTPUT
In main() a=20, b=30
In fun() a= 10
In fun() b= 40
In main() after calling fun() ~ b=30
#include <stdio.h>
#include <math.h>
int main()
{
float val;
float fVal,cVal;
fVal=floor(val);
cVal =ceil(val);
printf("floor value:%f \nceil value:%f\n",fVal,cVal);
return 0;
}
OUTPUT
Enter a float value: 34.5
floor value:34.000000
ceil value:35.000000
#include <stdio.h>
int main(){
int hour,minute,second;
return 0;
}
OUTPUT
Enter time (in HH:MM:SS) 09.56.01
Entered time is [Link]
return 0;
}
OUTPUT
1) Value of x: 100
2) Value of x: 200
3) Value of x: 300
#include<stdio.h>
int main()
{
int feet,inches;
printf("Enter the value of feet: ");
scanf("%d",&feet);
//converting into inches
inches=feet*12;
printf("Total inches will be: %d\n",inches);
return 0;
}
OUTPUT
Enter the value of feet: 12.5
Total inches will be: 144
#include <stdio.h>
int main()
{
int value=2567;
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
char ch;
//input character
printf("Enter the character: ");
scanf("%c",&ch);
OUTPUT
Enter the character: S
ASCII is = 83
29. C program to print How Many Inputs are taken from Keyboard using
Scanf?
#include <stdio.h>
int main(){
int count=0;
int num;
int arr[100],i=0;
while(num!=-1){
printf("Enter an integer number (-1 to exit): ");
count+=scanf("%d",&num);
arr[i++]=num;
}
printf("\nTotal Inputs (including 0) are: %d\n",count);
printf("Entered numbers are:\n");
for(i=0;i<count;i++){
printf("%d ",arr[i]);
}
printf("\n");
return 0;
}
OUTPUT
integer number (-1 to exit): 10
Enter an integer number (-1 to exit): 20
Enter an integer number (-1 to exit): 30
Enter an integer number (-1 to exit): 40
Enter an integer number (-1 to exit): -1
#include <stdio.h>
#define EMPLOYEE_PERCENTAGE 12.5f
#define EMPLOYER_PERCENTAGE 12.0f
int main(){
float basicPay;
float employeeFund,employerFund;
printf("Enter basic pay: ");
scanf("%f",&basicPay);
employeeFund=(basicPay/100)*EMPLOYEE_PERCENTAGE;
employerFund=(basicPay/100)*EMPLOYER_PERCENTAGE;
printf("Basic Pay: %f\n",basicPay);
printf("Employee contribution: %f\n",employeeFund);
printf("Employer Contribution: %f\n",employerFund);
return 0;
}
OUTPUT
Enter basic pay: 4500
Basic Pay: 4500.000000
Employee contribution: 562.500000
Employer Contribution: 540.000000
31. C program to set buffer with specific value using memset in C - Example of
memset()
#include <stdio.h>
#include <string.h>
int main()
{
unsigned char buffer[10]={0};
int i;
printf("buffer: %s\n",buffer);
//set value with space
memset(buffer,' ', 9); //last byte should be null
printf("buffer (memset with space): %s",buffer); printf(".\n");
//set value with 'x'
memset(buffer,'x', 9); //last byte should be null
printf("buffer (memset with x): %s",buffer); printf(".\n");
//set value with value 15
memset(buffer,15, 9); //last byte should be null
printf("buffer (memset with value 15): %s",buffer); printf(".\n");
printf("buffer (memset with value 15 printing integer values:\n*** LAST VALUE
WILL BE NULL ***):\n");
for(i=0;i<10;i++){
printf("%02d ",buffer[i]);
}
printf(".\n");
return 0;
}
OUTPUT
buffer:
buffer (memset with space): .
buffer (memset with x): xxxxxxxxx.
buffer (memset with value 15): #########.
buffer (memset with value 15 printing integer values:
*** LAST VALUE WILL BE NULL ***):
15 15 15 15 15 15 15 15 15 00 .
32. Write a C program to evaluate the net salary of an employee given the
following constraints
#include <stdio.h>
int main()
{
//variable to store values
float basic, da, hra, ta, others;
float pf,it;
float net_salary;
printf("Enter Basic Salary ($): ");
scanf("%f",&basic);
printf("Enter HRA ($): ");
scanf("%f",&hra);
printf("Enter TA ($): ");
scanf("%f",&ta);
printf("Enter others ($): ");
scanf("%f",&others);
da = (basic*12)/100;
pf = (basic*14)/100;
it = (basic*15)/100;
net_salary = basic + da + hra + ta + others - (pf+it);
printf("Net Salary is: $ %.02f\n",net_salary);
return 0;
}
OUTPUT
33. C program to swap two integer numbers without using temporary variable
#include <stdio.h>
int main()
{
int a,b;
//Input values
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
printf("Before swapping... a: %d, b: %d\n",a,b);
a = a+b; //step 1
b = a-b; //step 2
a = a-b; //step 3
printf("After swapping... a: %d, b: %d\n",a,b);
return 0;
}
OUTPUT
34. C program to read name and marital status of a girl and print her name
with Miss or Mrs
#include <stdio.h>
#include <string.h>
// main function
int main()
{
// Declare a char buffer to take input for name
char name[30]={0};
// Declare a char buffer to take input for answer
char YesNo[10]={0};
printf("Enter the name of a girl : ");
gets(name);
printf("Is the girl married (Y-Yes, N-No) : ");
gets(YesNo);
if((!strcmp(YesNo,"yes")) || (!strcmp(YesNo,"Y")))
printf("Her full name is : Mrs. %s",name);
else if((!strcmp(YesNo,"no")) || (!strcmp(YesNo,"N")))
printf("Her full name is : Miss %s",name);
else
printf("Marital status is wrong");
return 0;
}
OUTPUT
// main function
int main()
{
int number=0,A=0,B=0;
if(CheckDivision(number,A,B))
printf("%d is divisible by %d and %d\n",number,A,B);
else
printf("%d is not divisible by %d and %d\n",number,A,B);
return 0;
}
OUTPUT
#include <stdio.h>
int main(void) {
int n, sum;
//input value of n
printf("Enter the value of n: ");
scanf("%d", &n);
//initialize sum with 0
sum =0;
//use formula to get the sum from 0 to n
sum = n*(n+1)/2;
//print sum
printf("sum = %d\n", sum);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
unsigned char var1;
unsigned short var2;
unsigned int var3;
printf("Enter 1 byte value in Hexadecimal: ");
scanf("%x", &var1);
printf("Enter 2 bytes value in Hexadecimal: ");
scanf("%x", &var2);
printf("Enter 4 bytes value in Hexadecimal: ");
scanf("%x", &var3);
printf("Value of var1 in HEX: %X, Decimal: %d\n", var1,var1);
printf("Value of var2 in HEX: %X, Decimal: %d\n", var2,var2);
printf("Value of var3 in HEX: %X, Decimal: %d\n", var3,var3);
return 0;
}
OUTPUT
#include <stdio.h>
int main(void)
{
// declare variables
int a;
float b;
char c;
printf("Address of a: %p\n", &a);
printf("Address of b: %p\n", &b);
printf("Address of c: %p\n", &c);
return 0;
}
OUTPUT
Address of a: 0x7ffe6678d16c
Address of b: 0x7ffe6678d168
Address of c: 0x7ffe6678d167
#include <stdio.h>
int main(void)
{
printf("%d", printf ("Hello"));
return 0;
}
OUTPUT
Hello5
#include <stdio.h>
int main()
{
int num = 255;
int len = 0;
float val = 1.234567;
printf("Hello World");
printf("Hello world\nHow are you?");
printf("Hello \"World\", How are you?\n");
printf ("Hey I got 84.20%% in my final exams\n");
printf("num in octal format: %o\n", num);
printf ("num in hexadecimal format(lowercase) : %x\n", num);
printf ("num in hexadecimal format(uppercase) : %X\n", num);
printf ("Hello world, how are you?\
I love C programing language.\n");
printf ("The file is store at c:\\files\\word_files\n");
len = printf ("Hello\n");
printf ("Length: %d\n", len);
printf ("num (padded): %05d\n", num);
printf ("str1=\"%20s\", str2=\"%-20s\"\n", "Hello", "World");
printf("val = %.2f\n", val);
printf("num = %i \n", num);
printf("Address of num is: %p\n", &num);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int cp;
int sp;
int amount;
printf("Enter the cost price: ");
scanf("%d", &cp);
printf("Enter the selling price: ");
scanf("%d", &sp);
if (sp > cp) {
/*formula to find profit*/
amount = sp - cp; OUTPUT
printf("profit = %d", amount); Enter the cost price: 250
} Enter the selling price: 270
else if (cp > sp) { profit = 20
/*formula to find loss*/
amount = cp - sp;
printf("loss = %d", amount);
}
else {
printf("No profit no loss\n");
}
return 0;
}
42. Calculate the distance between two cities from kilometers to meters,
centimeters, feet and inches using C program
#include <stdio.h>
int main()
{
/*Declare the variables*/
int distance;
float meter;
float feet;
float inches;
float centimeter;
printf("Enter the distance between Gwalior and Delhi (in KM): ");
scanf("%d", &distance);
meter = distance * 1000;
feet = distance * 3280.84;
inches = distance * 39370.1;
centimeter = distance * 100000;
printf("Meter = %f\n", meter);
printf("Feet = %f\n", feet);
printf("Inches = %f\n", inches);
printf("Centimeters = %f\n", centimeter);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int distance;
float meter;
float feet;
float inches;
float centimeter;
printf(“Enter the distance between Gwalior and Delhi (in KM): “);
scanf(“%d”, &distance);
meter = distance * 1000;
feet = distance * 3280.84;
inches = distance * 39370.1;
centimeter = distance * 100000;
printf(“Meter = %f\n”, meter);
printf(“Feet = %f\n”, feet);
printf(“Inches = %f\n”, inches);
printf(“Centimeters = %f\n”, centimeter);
return 0;
}
OUTPUT
Enter the distance between Gwalior and Delhi (in KM): 55
Meter = 55000.000000
Feet = 180446.203125
Inches = 2165355.500000
Centimeters = 5500000.000000
#include <stdio.h>
int main()
{
float length;
float breadth;
float area;
float perimeter;
printf("Enter the length: ");
scanf("%f", &length);
printf("Enter the breadth: ");
scanf("%f", &breadth);
area = length * breadth;
perimeter = (2 * length) + (2 * breadth);
printf("Area of the rectangle: %.02f\n", area);
printf("Perimeter of rectangle: %.02f\n", perimeter);
return 0;
}
OUTPUT
#include <stdio.h>
OUTPUT
#include <stdlib.h>
Random number is: 1804289383
int main(void)
{
printf("Random number is: %d ", rand());
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int lower = 1, upper = 100, count = 10;
srand(time(0));
printf("The random numbers are: ");
for (int i = 0; i < count; i++) {
int num = (rand() % (upper - lower + 1)) + lower;
printf("%d ", num);
}
return 0;
}
46. C Example to subtract two integers without using Minus (-) operator
#include<stdio.h>
int main()
{
int a,b,sub;
//input numbers
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
printf("subtraction of %d-%d=%d",a,b,sub);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
float a=21.2;
double b=21.2;
if (a==b)
printf("Both values are equal");
else
printf("Both values are not equal");
return 0;
}
OUTPUT
Both values are not equal
#include <stdio.h>
int main()
{
printf("\t%d",printf("DCE06"));
return (0);
OUTPUT
DCE06 5
#include <stdio.h>
int main()
{
int a,b,rem;
printf("Enter first number :");
scanf("%d",&a);
printf("Enter second number :");
scanf("%d",&b);
rem=a-(a/b)*b;
printf("Remainder is = %d\n",rem);
return 0;
}
OUTPUT
Enter first number :26
Enter second number :14
Remainder is = 12
return 0;
}
#include <stdio.h>
int main()
{
unsigned char count;
for(count=32; count< 255; count+=1)
{
printf(" %3d - %c",count,count);
if(count % 6==0)
printf("\n");
}
return 0;
}
52. C program to swap two numbers using four different methods
#include <stdio.h>
int main()
{
int a,b,t;
printf(" Enter value of A ? ");
scanf("%d",&a);
printf(" Enter value of B ? ");
scanf("%d",&b);
printf("\n Before swapping : A= %d, B= %d",a,b);
return 0;
}
OUTPUT
Enter value of A ? 65
Enter value of B ? 67
Before swapping : A= 65, B= 67
After swapping (First method) : A= 67, B= 65
#include <stdio.h>
int isAlphaNumeric(char ch)
{
if ((ch >= '0' & ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
return 1;
return 0;
}
int main()
{
char ch = 0;
OUTPUT
Enter character: T
Given character is an alphanumeric character
54. C program to check a given character is a digit or not without using the
library function
#include <stdio.h>
int isDigit(char ch)
{
if (ch >= '0' && ch <= '9')
return 1;
return 0;
}
int main()
{
char ch = 0;
printf("Enter character: ");
scanf("%c", &ch);
if (isDigit(ch))
printf("Given character is a digit\n");
else
printf("Given character is not a digit\n");
return 0;
}
OUTPUT
Enter character: 5
Given character is a digit
#include <stdio.h>
return 0;
}
int main()
{
char ch1 = ' ';
char ch2 = '\t';
char ch3 = 't';
if (isWhiteSpace(ch1))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
if (isWhiteSpace(ch2))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
if (isWhiteSpace(ch3))
printf("Given character is a whitespace character\n");
else
printf("Given character is not a whitespace character\n");
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
char ch;
if (isUppercase(ch))
printf("Given character is an uppercase character\n");
else
printf("Given character is not an uppercase character\n");
return 0;
}
OUTPUT
Enter character: M
Given character is an uppercase character
return 0;
}
int main()
{
char ch;
if (isLowercase(ch))
printf("Given character is a lowercase character\n");
else
printf("Given character is not a lowercase character\n");
return 0;
}
OUTPUT
Enter character: v
Given character is not an uppercase character
#include <stdio.h>
int isPunctuation(char ch)
{
if (ch == '!' || ch == '\"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch
== '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch
== ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch
== '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}')
return 1;
return 0;
}
int main()
{
char ch;
if (isPunctuation(ch))
printf("Given character is a punctuation mark\n");
else
printf("Given character is not a punctuation mark\n");
return 0;
}
Enter character: T
Given character is not a punctuation mark
#include <stdio.h>
#include <ctype.h>
int isPunctuation(char ch)
{
if (ch == '!' || ch == '\"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch
== '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch
== ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch
== '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}')
return 1;
return 0;
}
return 0;
}
int main()
{
char ch1 = 'a';
char ch2 = 'A';
char ch3 = 95;
if (isPrintable(ch1) != 0)
printf("Given character is a printable character\n");
else
printf("Given character is not a printable character\n");
if (isPrintable(ch2) != 0)
printf("Given character is a printable character\n");
else
printf("Given character is not a printable character\n");
if (isPrintable(ch3) != 0)
printf("Given character is a printable character\n");
else
printf("Given character is not a printable character\n");
return 0;
}
OUTPUT
#include <stdio.h>
void stringLwr(char *s);
void stringUpr(char *s);
*****************************************
int main() * function name :stringLwr, stringUpr
{ * Parameter :character pointer s
char str[100]; * Description
stringLwr - converts string into lower case
printf("Enter any string : "); stringUpr - converts string into upper case
scanf("%[^\n]s",str); ******************************************
stringLwr(str);
printf("String after stringLwr : %s\n",str);
stringUpr(str);
printf("String after stringUpr : %s\n",str);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
char ch;
return 0;
}
OUTPUT
62. C program to print all punctuation marks without using library function
#include <stdio.h>
#include <ctype.h>
int main()
{
int cnt;
printf("Punctuation marks are: \n");
printf("\n");
return 0;
}
Output
Punctuation marks are:
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
63. C program to print all punctuation marks using the ispunct() function
#include <stdio.h>
#include <ctype.h>
int main()
{
int cnt;
printf("Punctuation marks are: \n");
printf("\n");
return 0;
}
Output
Punctuation marks are:
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
64. C program to print all printable characters using the isprint() function
#include <stdio.h>
#include <ctype.h>
int main()
{
int cnt;
printf("Printable characters are: \n");
printf("\n");
return 0;
}
Output
Printable characters are:
!"#$%&'()*+,-./
0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
[\]^_`abcdefghijklmnopqrst
uvwxyz{|}~
65. C program to print all printable characters without using the library
function
#include <stdio.h>
#include <ctype.h>
return 0;
}
return 0;
}
int main()
{
int cnt;
printf("Printable characters are: \n");
return 0;
}
Output
Printable characters are:
!"#$%&'()*+,-./
0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
[\]^`abcdefghijklmnopqrstu
vwxyz{|}~
#include <stdio.h>
return 0;
}
Output:
Beep sound started
Beep sound stopped
67. C program to convert a given number of days into days, weeks, and years
#include <stdio.h>
int main()
{
int ndays = 0;
int years = 0;
int weeks = 0;
int days = 0;
return 0;
}
Output
RUN 1:
Enter days: 367
1 years, 0 weeks and 2 days
RUN 2:
Enter days: 1280
3 years, 26 weeks and 3 day
RUN 3:
Enter days: 11
0 years, 1 weeks and 4 days
include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2, realPart, imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
return 0;
}
Run Code
Output
69. C program to find the GCD (Greatest Common Divisor) of two integers
#include <stdio.h>
int main()
{
int num1 = 0;
int num2 = 0;
int rem = 0;
int X = 0;
int Y = 0;
return 0;
}
Output
RUN 1:
Enter Number1: 10
Enter Number2: 20
Greatest Common Divisor is: 10
RUN 2:
Enter Number1: 10
Enter Number2: 225
Greatest Common Divisor is: 5
RUN 3:
Enter Number1: 110
Enter Number2: 17
Greatest Common Divisor is: 1
70. C program to find the LCM (Lowest Common Multiple) of two integers
#include <stdio.h>
int main()
{
int num1 = 0;
int num2 = 0;
int rem = 0;
int lcm = 0;
int X = 0;
int Y = 0;
printf("Enter Number1: ");
scanf("%d", &num1);
rem = X % Y;
while (rem != 0) {
X = Y;
Y = rem;
rem = X % Y;
}
return 0;
}
Output
RUN 1:
Enter Number1: 10
Enter Number2: 20
Lowest Common Multiple is: 20
RUN 2:
Enter Number1: 10
Enter Number2: 225
Lowest Common Multiple is: 450
RUN 3:
Enter Number1: 110
Enter Number2: 17
Lowest Common Multiple is: 1870
#include <stdio.h>
#include <math.h>
float calcuateAreaTriangle(int a, int b, int c)
{
float s = 0;
float area = 0;
s = (float)(a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}
int main()
{
int a = 0;
int b = 0;
int c = 0;
float area = 0;
printf("Enter the First edge of Triangle: ");
scanf("%d", &a);
printf("Enter the Second edge of Triangle: ");
scanf("%d", &b);
printf("Enter the Third edge of Triangle: ");
scanf("%d", &c);
area = calcuateAreaTriangle(a, b, c);
printf("Area of a triangle: %f\n", area);
return 0;
}
OUTPUT
72. C program to calculate the area of a triangle given base and height
#include < stdio.h >
int main()
{
float base, height, area;
printf("Enter length of base of Triangle\n");
scanf("%f", &base);
printf("Enter length of height of Triangle\n");
scanf("%f", &height);
area = (base * height) / 2.0;
printf("Area of Triangle is %0.2f\n", area);
return 0;
}
OUTPUT
Enter length of base of Triangle
15
Enter length of height of Triangle
25
Area of Triangle is 187.50
#include <stdio.h>
int main(){
int b1, b2, height;
float area;
printf("Enter Base One: ");
scanf("%d", &b1);
printf("Enter Base Two: ");
scanf("%d", &b2);
printf("Enter the height: ");
scanf("%d", &height);
area = 0.5 * (b1 + b2) * height;
printf("Area of Trapezium: %.2f", area);
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
float diagonal1, diagonal2;
float area;
output
#include <stdio.h>
int main()
{
float base, altitude;
float area;
printf("Enter base and altitude of the given Parallelogram: \n ");
scanf("%f%f", &base, &altitude);
area = base * altitude;
printf("Area of Parallelogram is: %.3f\n", area);
return 0;
}
OUTPUT
Enter base and altitude of the given Parallelogram:
17 19
Area of Parallelogram is: 323.000
#include <stdio.h>
int main(){
int side;
float area;
OUTPUT
Enter the side of the cube: 2
Surface Area of Cube: 24.00
#include <stdio.h>
int main(){
int side;
float volume;
OUTPUT
78. C program to find the Surface Area and Volume of the Cylinder
#include<stdio.h>
#include<math.h>
int main(){
float r,h;
float surface_area,volume;
return 0;
}
OUTPUT
Enter size of radius and height of a cylinder: 4 10
Surface area of cylinder is: 351.858
Volume of cylinder is: 502.655
79. C program to calculate the surface area, volume, and space diagonal of
cuboids
#include <stdio.h>
#include <math.h>
int main()
{
float height = 0;
float width = 0;
float length = 0;
float volume = 0;
float area = 0;
float diagonal = 0;
OUTPUT
Enter the height: 10
Enter the width: 20
Enter the length: 30
Volume of Cuboids is: 6000.000000
Surface area of Cuboids is: 1700.000000
Space diagonal of Cuboids is: 1020.000000
#include <stdio.h>
#include <math.h>
int main()
{
float height = 0;
float radius = 0;
float volume = 0;
float area = 0;
printf("Enter the height: ");
scanf("%f", &height);
printf("Enter the radius: ");
scanf("%f", &radius);
volume = (1.0 / 3) * (3.14) * radius * radius * height;
area = (3.14) * radius * (radius + sqrt(radius * radius + height * height));
printf("Volume of Cone: %f\n", volume);
printf("Surface area of Cone: %f\n", area);
return 0;
}
OUTPUT
Enter the height: 12.3
Enter the radius: 4
Volume of Cone: 205.984009
Surface area of Cone: 212.691849
#include <stdio.h>
#include <math.h>
int main()
{
float radius = 0;
float volume = 0;
float area = 0;
printf("Enter the radius: ");
scanf("%f", &radius);
volume = (4.0 / 3) * (3.14) * pow(radius, 3);
area = 4 * (3.14) * pow(radius, 2);
printf("Volume of Sphere %f\n", volume);
printf("Surface area of Sphere: %f\n", area);
return 0;
}
OUTPUT
82. C program to calculate the mean, variance, and standard deviation of real
numbers
#include <stdio.h>
#include <math.h>
int main()
{
float arr[5] = { 12.5, 14.5, 13.2, 8.95, 17.89 };
float sum;
float mean;
float variance;
float deviation;
int i = 0;
for (i = 0; i < 5; i++)
sum = sum + arr[i];
mean = sum / 5;
sum = 0;
for (i = 0; i < 5; i++) {
sum = sum + pow((arr[i] - mean), 2);
}
variance = sum / 5;
deviation = sqrt(variance);
printf("Mean of elements : %.2f\n", mean);
printf("variance of elements: %.2f\n", variance);
printf("Standard deviation : %.2f\n", deviation);
return 0;
}
Output
Mean of elements : 13.41
variance of elements: 8.40
Standard deviation : 2.90
83. C program to read coordinate points and determine its quadrant
#include <stdio.h>
void main()
{
int x, y;
printf("Enter the values for X and Y\n");
scanf("%d %d", &x, &y);
if (x > 0 && y > 0)
printf("point (%d, %d) lies in the First quandrant\n");
else if (x < 0 && y > 0)
printf("point (%d, %d) lies in the Second quandrant\n");
else if (x < 0 && y < 0)
printf("point (%d, %d) lies in the Third quandrant\n");
else if (x > 0 && y < 0)
printf("point (%d, %d) lies in the Fourth quandrant\n");
else if (x == 0 && y == 0)
printf("point (%d, %d) lies at the origin\n");
}
OUTPUT
#include <stdio.h>
int getFactorial(int num)
{
int f = 1;
int i = 0;
if (num == 0)
return 1;
for (i = 1; i <= num; i++)
f = f * i;
return f;
}
int main()
{
int n = 0;
int r = 0;
int nCr = 0;
printf("Enter the value of N: ");
scanf("%d", &n);
printf("Enter the value of R: ");
scanf("%d", &r);
nCr = getFactorial(n) / (getFactorial(r) * getFactorial(n - r));
printf("The nCr is: %d\n", nCr);
return 0;
}
OUTPUT
Enter the value of N: 7
Enter the value of R: 3
The nCr is: 35
#include <stdio.h>
int getFactorial(int num)
{
int f = 1;
int i = 0;
if (num == 0)
return 1;
for (i = 1; i <= num; i++)
f = f * i;
return f;
}
int main()
{
int n = 0;
int r = 0;
int nPr = 0;
printf("Enter the value of N: ");
scanf("%d", &n);
printf("Enter the value of R: ");
scanf("%d", &r);
nPr = getFactorial(n) / getFactorial(n - r);
printf("The nPr is: %d\n", nPr);
return 0;
}
OUTPUT
Enter the value of N: 7
Enter the value of R: 3
The nPr is: 210
#include <stdio.h>
int binaryProduct(int binNum1, int binNum2)
{
int i = 0;
int rem = 0;
int product = 0;
int sum[20] = { 0 };
while (binNum1 != 0 || binNum2 != 0) {
sum[i] = (binNum1 % 10 + binNum2 % 10 + rem) % 2;
rem = (binNum1 % 10 + binNum2 % 10 + rem) / 2;
binNum1 = binNum1 / 10;
binNum2 = binNum2 / 10;
i = i + 1;
}
if (rem != 0)
sum[i] = rem;
while (i >= 0) {
product = product * 10 + sum[i];
i = i - 1;
}
return product;
}
int main()
{
long binNum1 = 0;
long binNum2 = 0;
long product = 0;
int digit = 0;
int factor = 1;
printf("Enter Number1: ");
scanf("%ld", &binNum1);
printf("Enter Number2: ");
scanf("%ld", &binNum2);
while (binNum2 != 0) {
digit = binNum2 % 10;
if (digit == 1) {
binNum1 = binNum1 * factor;
product = binaryProduct(binNum1, product);
}
else {
binNum1 = binNum1 * factor;
}
binNum2 = binNum2 / 10;
factor = 10;
}
printf("Product of numbers: %ld", product);
return 0;
}
OUTPUT
Enter Number2: 1110
Enter Number2: 10100
Product of numbers: 100011000
87. C program to extract the last two digits from a given year
#include <stdio.h>
int main()
{
int year = 0;
int res = 0;
printf("Enter year: ");
scanf("%d", &year);
res = year % 100;
printf("Result is: %02d", res);
return 0;
} OUTPUT
Enter year: 2021
Result is: 21