C Programming Language
C Programming Language
decrement statement in C?
There are actually two ways you can do this. One is to use the increment
operator ++ and decrement operator –. For example, the statement “x++”
means to increment the value of x by 1. Likewise, the statement “x –”
means to decrement the value of x by 1. Another way of writing increment
statements is to use the conventional + plus sign or – minus sign. In the
case of “x++”, another way to write it is “x = x +1”.
while (a<=100) {
a++;
5) What is a stack?
A stack is one form of a data structure. Data is stored in stacks using the
FILO (First In Last Out) approach. At any particular instance, only the top of
the stack is accessible, which means that in order to retrieve data that is
stored inside the stack, those on the upper part should be extracted first.
Storing data in a stack is also referred to as a PUSH, while data retrieval is
referred to as a POP.
19) What are header files and what are its uses in C
programming?
Header files are also known as library files. They contain two essential
things: the definitions and prototypes of functions being used in a
program. Simply put, commands that you use in C programming are
actually functions that are defined from within each header files. Each
header file contains a set of functions. For example: stdio.h is a header file
that contains definition and prototypes of commands like printf and scanf.
23) Can I use “int” data type to store the value 32768?
Why?
No. “int” data type is capable of storing values from -32768 to 32767. To
store 32768, you can use “long int” instead. You can also use “unsigned
int”, assuming you don’t intend to store negative values.
25) Why is it that not all header files are declared in every C
program?
The choice of declaring a header file at the top of each C program would
depend on what commands/functions you will be using in that program.
Since each header file contains different function definitions and
prototype, you would be using only those header files that would contain
the functions you will need. Declaring all header files in every program
would only increase the overall file size and load of the program, and is not
considered a good programming style.
12
123
1234
12345
Answer:
for (a=1; a<=5; i++) {
printf("%d",b);
printf("\n");
}
31) What is wrong in this statement?
scanf(“%d”,whatnumber);
An ampersand & symbol must be placed before the variable name
whatnumber. Placing & means whatever integer value is entered by the
user is stored at the “address” of the variable name. This is a common
mistake for programmers, often leading to logical errors.
printf("EVEN");
else
printf("ODD");
38) What does the format %10.2 mean when included in a
printf statement?
This format is used for two things: to set the number of spaces allotted for
the output number and to set the number of decimal places. The number
before the decimal point is for the allotted space, in this case it would allot
10 spaces for the output number. If the number of space occupied by the
output number is less than 10, addition space characters will be inserted
before the actual output number. The number after the decimal point sets
the number of decimal places, in this case, it’s 2 decimal spaces.
39) What are logical errors and how does it differ from
syntax errors?
Program that contains logical errors tend to pass the compilation process,
but the resulting output may not be the expected one. This happens when
a wrong formula was inserted into the code, or a wrong sequence of
commands was performed. Syntax errors, on the other hand, deal with
incorrect commands that are misspelled or not recognized by the
compiler.
The outcome will be TRUE. Since the value of s is 10, s >= 10 evaluates to
TRUE because s is not greater than 10 but is still equal to 10. s< 25 is also
TRUE since 10 is less then 25. Just the same, s!=12, which means s is not
equal to 12, evaluates to TRUE. The && is the AND operator, and follows
the rule that if all individual conditions are TRUE, the entire statement is
TRUE.
printf("number is positive");
else
81) What does the characters “r” and “w” mean when
writing programs that will make use of files?
“r” means “read” and will open a file as input wherein data is to be
retrieved. “w” means “write”, and will open a file for output. Previous data
that was stored on that file will be erased.
82) What is the difference between text files and binary
files?
Text files contain data that can easily be understood by humans. It
includes letters, numbers and other characters. On the other hand, binary
files contain 1s and 0s that only computers can interpret.
temp = num1;
num1 = num2;
num2 = temp;
100) What is the use of a semicolon (;) at the end of every
program statement?
It has to do with the parsing process and compilation of the code. A
semicolon acts as a delimiter, so that the compiler knows where each
statement ends, and can proceed to divide the statement into smaller
elements for syntax checking.
int main()
{
// Print Name
printf("Name : Alexandra Abramov\n");
Explanation:
return(0);: This line indicates the end of the main function and
returns 0.
Sample Output:
Name : Alexandra Abramov
DOB : July 14, 1975
Mobile : 99-9999999999
#include <stdio.h>
int main(int argc, char** argv) {
// Check for C standard version
#if __STDC_VERSION__ >= 201710L
printf("We are using C18!\n");
#elif __STDC_VERSION__ >= 201112L
printf("We are using C11!\n");
#elif __STDC_VERSION__ >= 199901L
printf("We are using C99!\n");
#else
printf("We are using C89/C90!\n");
#endif
Explanation:
int main(int argc, char** argv): This is the main function with
command-line arguments argc and argv. However, in this code,
these arguments are not used.
return 0;: This line indicates the end of the main function and
returns 0 to the operating system, indicating a successful
program execution.
Sample Output:
We are using C18!
Block of 'F':
C Code:
#include <stdio.h>
int main()
{
// Print a line of hashes
printf("######\n");
Pictorial Presentation:
#include <stdio.h>
int main()
{
// Declare and initialize character variables
char char1 = 'X';
char char2 = 'M';
char char3 = 'L';
Sample Output:
The reverse of XML is LMX
C Code:
#include <stdio.h>
/*
Variables to store the width and height of a rectangle in inches
*/
int width;
int height;
int main() {
/* Assigning values to height and width */
height = 7;
width = 5;
return(0);
}
Explanation:
Sample Output:
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches
C Code:
#include <stdio.h>
int main() {
int radius; /* Variable to store the radius of the circle */
float area, perimeter; /* Variables to store the area and
perimeter of the circle */
radius = 6; /* Assigning a value to the radius */
return(0);
}
Explanation:
o float area and float perimeter: Will store the calculated area
and perimeter of the circle.
Sample Output:
Perimeter of the Circle = 37.680000 inches
Area of the Circle = 113.040001 square inches
C Code:
#include <stdio.h>
int main()
return 0;
Copy
Sample Output:
a + c = 212
x + c = 89.134590
dx + x = 3.276183
((int) dx) + ax = 1234567891
a + x = 127.134590
s + b = 16388
ax + b = 1234580235
s + c = 4130
ax + c = 1234567977
ax + ux = 3776135780
Test Data :
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3
#include <stdio.h>
int main()
return 0;
Explanation:
It then converts:
Sample Output:
Years: 3
Weeks: 33
Days: 3
Write a C program that accepts two integers from the user and
calculates the sum of the two integers.
C Code:
#include <stdio.h>
int main()
int x, y, sum; // Declare variables for two integers and their sum
scanf("%d", &x);
scanf("%d", &y);
Copy
Sample Output:
Input the first integer: 25
Input the second integer: 38
10. Write a C program that accepts two integers from the user
and calculates the product of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 15
Expected Output:
Product of the above two integers = 375
C Code:
#include <stdio.h>
int main()
scanf("%d", &x);
scanf("%d", &y);
result = x * y; // Calculate the product of 'x' and 'y'
Copy
Sample Output:
Input the first integer: 25
C Code:
#include <stdio.h>
int main()
scanf("%lf", &wi1);
// Prompt user for count of item 1
scanf("%lf", &ci1);
scanf("%lf", &wi2);
scanf("%lf", &ci2);
return 0;
Sample Output:
Weight - Item1: 15
No. of item1: 5
Weight - Item2: 25
No. of item2: 4
Average Value = 19.444444
12. Write a C program that accepts an employee's ID, total
worked hours in a month and the amount he received per hour.
Print the ID and salary (with two decimal places) of the employee
for a particular month.
Test Data :
Input the Employees ID(Max. 10 chars): 0342
Input the working hrs: 8
Salary amount/hr: 15000
Expected Output:
Employees ID = 0342
Salary = U$ 120000.00
C Code:
#include <stdio.h>
int main() {
scanf("%s", &id);
scanf("%d", &hour);
// Prompt user for hourly salary
scanf("%lf", &value);
return 0;
Copy
Sample Output:
Input the Employees ID(Max. 10 chars): 0342
Employees ID = 0342
Salary = U$ 120000.00
13. Write a C program that accepts three integers and finds the
maximum of three.
Test Data :
Input the first integer: 25
Input the second integer: 35
Input the third integer: 15
Expected Output:
Maximum value of three integers: 35
C Code:
#include <stdio.h>
#include <stdlib.h>
int main()
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &z);
printf("\n");
return 0;
Copy
Sample Output:
Input the first integer: 25
C Code:
#include <stdio.h>
int main()
scanf("%d",&x);
scanf("%f", &y);
printf("\n");
return 0;
Copy
Sample Output:
Input total distance in km: 350
Input total fuel spent in liters: 5
Average consumption (km/lt) 70.000
Formula:
C Code:
#include <stdio.h>
#include <math.h>
int main() {
scanf("%f", &x1);
scanf("%f", &y1);
scanf("%f", &x2);
scanf("%f", &y2);
// Calculate squared distance between points
gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
printf("\n");
return 0;
Copy
Explanation:
o float x1, y1, x2, y2: These variables will store the
coordinates of two points in the form (x, y) where (x1, y1)
are the coordinates of the first point, and (x2, y2) are the
coordinates of the second point.
o It prints "Distance between the said points: " along with the
calculated square root of 'gdistance' using sqrt(gdistance).
Sample Output:
Input x1: 25
Input y1: 15
Input x2: 35
Input y2: 10
Distance between the said points: 11.1803
C Code:
#include <stdio.h>
int main() {
scanf("%d",&amt);
total = (int)amt/100;
printf("There are:\n");
amt = amt-(total*100);
total = (int)amt/50;
amt = amt-(total*50);
total = (int)amt/20;
amt = amt-(total*20);
total = (int)amt/10;
amt = amt-(total*10);
total = (int)amt/5;
amt = amt-(total*5);
total = (int)amt/2;
amt = amt-(total*2);
total = (int)amt/1;
return 0;
Copy
Explanation:
Sample Output:
Input the amount: 375
There are:
3 Note(s) of 100.00
1 Note(s) of 50.00
1 Note(s) of 20.00
0 Note(s) of 10.00
1 Note(s) of 5.00
0 Note(s) of 2.00
0 Note(s) of 1.00
C Code:
#include <stdio.h>
int main() {
scanf("%d", &sec);
h = (sec/3600);
m = (sec -(3600*h))/60;
s = (sec -(3600*h)-(m*60));
printf("H:M:S - %d:%d:%d\n",h,m,s);
return 0;
Copy
Sample Output:
Input seconds: 25300
H:M:S - 7:1:40
C Code:
#include <stdio.h>
int main() {
scanf("%d", &ndays);
y = (int) ndays/365;
ndays = ndays-(365*y);
m = (int)ndays/30;
d = (int)ndays-(m*30);
return 0;
Copy
Sample Output:
Input no. of days: 2535
6 Year(s)
11 Month(s)
15 Day(s)
Test Data :
Input the second integer: 35
Input the third integer: 15
Input the fourth integer: 46
Expected Output:
Wrong values
C Code:
#include <stdio.h>
int main() {
scanf("%d", &p);
scanf("%d", &q);
scanf("%d", &r);
scanf("%d", &s);
if((q > r) && (s > p) && ((r+s) > (p+q)) && (r > 0) && (s > 0) &&
(p%2 == 0))
{
printf("\nCorrect values\n");
else {
printf("\nWrong values\n");
return 0;
Sample Output:
Input the first integer: 25
Wrong values
C Code:
#include <stdio.h>
#include <math.h>
int main() {
scanf("%lf", &a);
scanf("%lf", &b);
scanf("%lf", &c);
double x, y;
}
else {
return 0;
Copy
Sample Output:
Input the first number(a): 25
C Code:
#include <stdio.h>
int main() {
scanf("%d", &x);
if(x >=0 && x <= 20) // Check if 'x' is in the range [0, 20]
else if(x >=21 && x <= 40) // Check if 'x' is in the range (21,40]
else if(x >=41 && x <= 60) // Check if 'x' is in the range (41,60]
else if(x >61 && x <= 80) // Check if 'x' is in the range (61,80]
else
return 0;
Copy
Sample Output:
Input an integer: 15
Range [0, 20]
22. Write a C program that reads 5 numbers and sums all odd
values between them.
Test Data :
Input the first number: 11
Input the second number: 17
Input the third number: 13
Input the fourth number: 12
Input the fifth number: 5
Expected Output:
Sum of all odd values: 46
C Code:
#include <stdio.h>
int main() {
// Prompt user for five numbers and store them in the array
scanf("%d", &numbers[0]);
printf("\nInput the second number: ");
scanf("%d", &numbers[1]);
scanf("%d", &numbers[2]);
scanf("%d", &numbers[3]);
scanf("%d", &numbers[4]);
// Loop through the numbers to find and sum the odd ones
if((numbers[j]%2) != 0)
total += numbers[j];
printf("\n");
return 0;
Copy
Sample Output:
Input the first number: 11
C Code:
#include <stdio.h>
int main() {
// Prompt user for the side lengths and store in 'x', 'y', and 'z'
scanf("%f", &x);
scanf("%f", &y);
if(x < (y+z) && y < (x+z) && z < (y+x)) // Check if the sides can
form a triangle
else
return 0;
Copy
Sample Output:
Input the first number: 25
Perimeter = 75.0
C Code:
#include <stdio.h>
int main() {
scanf("%d", &x);
scanf("%d", &y);
if(x > y)
int temp;
x = y;
y = temp;
{
printf("\nMultiplied!\n"); // Print message if 'x' is a factor
of 'y'
else
return 0;
Copy
Sample Output:
Input the first number: 5
Multiplied!
C Code:
#include <stdio.h>
int main() {
scanf("%d", &mno);
switch(mno) {
return 0;
Copy
Sample Output:
Input a number between 1 to 12 to get the month name: 8
August
C Code:
#include <stdio.h>
int main() {
return 0;
}
Sample Output:
Even numbers between 1 to 50 (inclusive):
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46
48 50
C Code:
#include <stdio.h>
int main() {
// Prompt user for five numbers and store them in the array
scanf("%f", &numbers[0]);
scanf("%f", &numbers[1]);
scanf("%f", &numbers[3]);
scanf("%f", &numbers[4]);
printf("\n");
return 0;
}
Copy
Sample Output:
Input the first number: 5
C Code:
#include <stdio.h>
int main() {
scanf("%f", &numbers[0]);
scanf("%f", &numbers[1]);
scanf("%f", &numbers[2]);
scanf("%f", &numbers[3]);
scanf("%f", &numbers[4]);
return 0;
Copy
Sample Output:
Input the first number: 5
29. Write a C program that read 5 numbers and sum of all odd
values between them.
Test Data :
Input the first number: 5
Input the second number: 7
Input the third number: 9
Input the fourth number: 10
Input the fifth number: 13
Expected Output:
Sum of all odd values: 34
C Code:
#include <stdio.h>
int main() {
int j, numbers[5], total=0; // Declare array to store 5 numbers
and variable for total
scanf("%d", &numbers[0]);
scanf("%d", &numbers[1]);
scanf("%d", &numbers[2]);
scanf("%d", &numbers[3]);
scanf("%d", &numbers[4]);
return 0;
Copy
Sample Output:
Input the first number: 5
30. Write a C program to find and print the square of all the even
values from 1 to a specified value.
Test Data :
List of square of each one of the even values from 1 to a 4 :
Expected Output:
2^2 = 4
4^2 = 16
C Code:
#include <stdio.h>
int main() {
return 0;
Copy
Sample Output:
List of square of each one of the even values from 1 to a 4 :
2^2 = 4
4^2 = 16
C Code:
#include <stdio.h>
int main() {
if(x == 0){
printf("Positive\n");
printf("Negative Odd\n");
printf("Negative Even\n");
printf("Positive Odd\n");
printf("Positive Even\n");
return 0;
Copy
Sample Output:
Input an integer: 13
Positive Odd
32. Write a C program to print all numbers between 1 and 100
which are divided by a specified number and the remainder will
be 3.
Test Data :
Input an integer: 25
Expected Output:
3
28
53
78
C Code:
#include <stdio.h>
int main() {
return 0;
}
Copy
Input data: 25
Sample Output:
Input an integer: 3
28
53
78
33. Write a C program that accepts some integers from the user
and finds the highest value and the input position.
Test Data :
Input 5 integers:
5
7
15
23
45
Expected Output:
Highest value: 45
Position: 5
C Code:
#include <stdio.h>
#define MAX 5
int main()
return 0;
Copy
Sample Output:
Input 5 integers:
5
7
15
23
45
Highest value: 45
Position: 5
C Code:
#include <stdio.h>
int main() {
if (x < y) {
if ((i % 2) != 0) {
}
}
return 0;
Copy
Sample Output:
Input a pair of numbers (for example 10,2):
Input first number of the pair: 10
C Code:
#include <stdio.h>
int main() {
if (x > y) {
} else {
printf("\n");
return 0;
Copy
Sample Output:
Input a pair of numbers (for example 10,2 : 2,10):
Input first number of the pair: 10
C Code:
#include <stdio.h>
int main() {
while (x != 0) {
if (pass == 1234) {
} else {
printf("\n");
return 0;
}
Copy
Sample Output:
Input the password: 1234
Correct password
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int x, y;
// Prompt for user input
printf("\nx: ");
scanf("%d", &x);
printf("y: ");
scanf("%d", &y);
printf("Quadrant-I(+,+)\n");
printf("Quadrant-II(+,-)\n");
printf("Quadrant-III(-,-)\n");
printf("Quadrant-IV(-,+)\n");
return 0;
Copy
Sample Output:
Input the Coordinate(x,y):
x: 25
y: 15
Quadrant-I(+,+)
38. Write a program that reads two numbers and divides the first
number by the second number. If division is not possible print
"Division is not possible".
Test Data :
Input two numbers:
x: 25
y: 5
Expected Output: 5.0
C Code:
#include <stdio.h>
int main() {
int x, y;
float div_result;
printf("\nx: ");
scanf("%d", &x);
printf("y: ");
scanf("%d", &y);
if(y != 0) {
div_result = x/y;
printf("%.1f\n", div_result);
} else {
return 0;
Copy
Sample Output:
Input two numbers:
x: 25
y: 5
5.0
C Code:
#include <stdio.h>
int main() {
scanf("%d", &x);
if(x > y) {
temp = y;
y = x;
x = temp;
if((i % 17) != 0) {
sum += i;
return 0;
Copy
Sample Output:
Input the first integer: 50
40. Write a C program that finds all integer numbers that divide
by 7 and have a remainder of 2 or 3 between two given integers.
Test Data :
Input the first integer: 25
Input the second integer: 45
Expected Output:
30
31
37
38
44
C Code:
#include <stdio.h>
int main() {
scanf("%d", &x);
scanf("%d", &y);
if(x > y) {
temp = y;
y = x;
x = temp;
}
if((i%7) == 2 || (i%7) == 3) {
printf("%d\n", i);
return 0;
Copy
Sample Output:
Input the first integer: 25
C Code:
#include <stdio.h>
int main() {
int a, i, j = 1, x = 0;
scanf("%d", &a);
while(x < 3) {
x++;
printf("\n");
return 0;
}
Copy
Sample Output:
Input number of lines: 5
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
C Code:
#include <stdio.h>
int main() {
int a, i, j = 1, x = 0;
scanf("%d", &a);
return 0;
Copy
Sample Output:
Input number of lines: 5
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
C Code:
#include <stdio.h>
int main() {
int x, y, i, j, l;
// Prompt for user input
scanf("%d", &x);
scanf("%d", &y);
l++;
printf("\n");
return 0;
Copy
Sample Output:
Input number of lines: 5
Number of numbers in a line: 6
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
44. Write a C program to calculate the average mathematics
marks of some students. Input 0 (excluding to calculate the
average) or a negative value to terminate the input process.
Test Data :
Input Mathematics marks (0 to terminate): 10
15
20
25
0
Expected Output:
Average marks in Mathematics: 17.50
C Code:
#include <stdio.h>
int main() {
float f;
for(i = 0; ; i++) {
scanf("%d", &marks[i]);
if(marks[i] <= 0) {
break;
a++;
total += marks[i];
}
f = (float)total/(float)a;
return 0;
Copy
Sample Output:
Input Mathematics marks (0 to terminate): 10
15
20
25
0
Average marks in Mathematics: 17.50
45. Write a C program to calculate the value of S where S = 1 +
1/2 + 1/3 + … + 1/50.
Expected Output:
Value of S: 4.50
C Code:
#include <stdio.h>
int main() {
float S = 0;
int i;
S += (float)1/i;
}
return 0;
Copy
Sample Output:
Value of S: 4.50
C Code:
#include <stdio.h>
int main() {
d = (i/j);
s += d;
j = j*2;
}
// Print the result
return 0;
Copy
Sample Output:
Value of series: 4.62
C Code:
#include <stdio.h>
int main() {
int x, i;
scanf("%d", &x);
// Print all the divisors of x
if((x%i) == 0){
printf("\n%d", i);
printf("\n");
return 0;
Copy
Sample Output:
Input an integer: 45
All the divisor of 45 are:
1
15
45
Expected Output:
Array values are:
n[0] = 25
n[1] = 45
n[2] = 35
n[3] = 65
n[4] = 15
C Code:
#include <stdio.h>
int main() {
int n[5], i, x;
scanf("%d", &x);
if(x > 0) {
n[i] = x;
} else {
n[i] = 100;
return 0;
Copy
Sample Output:
Input the 5 members of the array:
25
45
35
65
15
Array values are:
n[0] = 25
n[1] = 45
n[2] = 35
n[3] = 65
n[4] = 15
#include <stdio.h>
int main() {
int n[5], i, x;
scanf("%d", &x);
n[i] = x;
x = 3 * x;
return 0;
Copy
Sample Output:
Input the first number of the array:
5
n[0] = 5
n[1] = 15
n[2] = 45
n[3] = 135
n[4] = 405
C Code:
#include <stdio.h>
int main() {
int i;
scanf("%f", &N[i]);
// Iterate through the array and print elements less than MAX
return 0;
Copy
Sample Output:
Input the 5 members of the array:
15
25
4
35
40
A[2] = 4.0
Expected Output:
array_n[0] = 35
array_n[1] = 30
array_n[2] = 25
array_n[3] = 20
array_n[4] = 15
C Code:
#include <stdio.h>
#define AL 5
int main() {
scanf("%d", &array_n[i]);
// Swap the first half of the array with the second half
array_n[i] = array_n[AL-(i+1)];
array_n[AL-(i+1)] = temp;
return 0;
Copy
Sample Output:
Input the 5 members of the array:
15
20
25
30
35
array_n[0] = 35
array_n[1] = 30
array_n[2] = 25
array_n[3] = 20
array_n[4] = 15
52. Write a C program to read an array of length 6 and find the
smallest element and its position.
Test Data:
Input the length of the array: 5 Input the array elements:
25
35
20
14
45
Expected Output:
Smallest Value: 14
Position of the element: 3
C Code:
#include <stdio.h>
int main() {
scanf("%d", &e);
int v[e];
scanf("%d", &v[i]);
sval = v[0];
position = 0;
sval = v[i];
position = i;
return 0;
Copy
Sample Output:
Input the length of the array: 5
C Code:
#include<stdio.h>
int main() {
int p, r, t, int_amt;
int_amt = (p * r * t) / 100;
return 0;
Copy
Sample Output:
Input Data: p = 10000, r = 10% , t = 12 year
Input principle, Rate of interest & time to find simple interest:
Simple interest = 12000
#include <stdio.h>
int main() {
scanf("%lf", &cm);
inch = cm / INCH_TO_CM;
Copy
Sample Output:
Input Data: 500cms
Input the distance in cm:
Distance of 500.00 cms is = 196.85 inches
Applications of Swapping
C Code:
#include<stdio.h>
int main()
int x, y;
scanf("%d%d",&x,&y);
x=x+y;
y=x-y;
x=x-y;
return 0;
}
Copy
Output:
Input value for x & y:
Before swapping the value of x & y: 5 7
After swapping the value of x & y: 7 5
Explanation:
o scanf("%d%d", &x, &y); reads the input values from the user
and stores them in x and y.
Code:
#include <stdio.h>
int main() {
int x, y;
return 0;
}
Copy
Output:
Input value for x & y:
2 3
Before swapping the value of x & y: 2 3
After swapping the value of x & y: 3 2
Explanation:
o scanf("%d%d", &x, &y); reads the input values from the user
and stores them in x and y.
56. Write a C program to shift given data by two bits to the left.
Input value : 2
Read the integer from keyboard-
Integer value = 2
The left shifted data is = 16
C Code:
#include<stdio.h>
int main() {
int a, b;
scanf("%d",&a);
a <<= 2;
b = a;
Copy
Sample Output:
Read the integer from keyboard-
Integer value = 2
The left shifted data is = 8
#include<stdio.h>
int main() {
scanf("%d", &num);
x = num % 10;
r_num = r_num * 10 + x;
return 0;
Copy
Sample Output:
Input a number:
The original number = 234
The reverse of the said number = 432
C Code:
#include <stdio.h>
int main() {
max = a1;
max = a2;
max = a3;
else
max = a4;
min = a1;
min = a2;
min = a3;
else
min = a4;
return 0;
Copy
Sample Output:
Input four numbers: 1.54 1.236 1.3625 1.002
Difference is 0.5380
C Code:
#include<stdio.h>
int main() {
scanf("%d", &num);
printf("1 + ");
// Print the series
sum = sum + i;
return 0;
Copy
Sample Output:
Input any number: 1 + 1/0
Sum = 1/0
C Code:
#include <stdio.h>
int main() {
return 0;
Copy
Sample Output:
Sun = 0
Mon = 1
Tue = 2
Wed = 3
Thu = 4
Fri = 5
Sat = 6
C Code:
#include <stdio.h>
#include <math.h>
int main() {
double x, tval;
scanf("%lf", &x);
if (x != 0.0) {
tval = sin(1/x);
} else {
// Display error message if x is zero
return 0;
Copy
Sample Output:
Input value of x:
Value of sin(1/x) is 0.9995
C Code:
#include <stdio.h>
int main() {
int a, x = 0, y;
y = a;
} else {
x += y % 10;
y /= 10;
x += y % 10;
y /= 10;
x += y % 10;
return 0;
Copy
Sample Output:
Input a positive number less than 500:
Sum of the digits of 347 is 14
63. Write a C program that accepts a positive integer n less than
100 from the user. It prints out the sum of 14 + 24 + 44 + 74 +
114 + • • • + m4. In this case, m is less than or equal to n. Print an
appropriate message.
Input a positive number less than 100: 68
Sum of the series is 37361622
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int i, j, n, sum_int = 0;
scanf("%d", &n);
printf("Wrong input\n");
return 0;
j = 1;
sum_int += j * j * j * j;
j += i;
return 0;
Sample Output:
Input a positive number less than 100: 68
Sum of the series is 37361622
64. Write a C program that accepts integers from the user until a
zero or a negative number, displays the number of positive values,
the minimum value, the maximum value, and the average value.
Input a positive integer:
Input next positive integer: 15
Input next positive integer: 25
Input next positive integer: 37
Input next positive integer: 43
Number of positive values entered is 4
Maximum value entered is 43
Minimum value entered is 15
Average value is 30.0000
C Code:
#include <stdio.h>
int main() {
double avg;
scanf("%d", &a);
if (a <= 0) {
return 0;
min_num = a;
max_num = a;
// Loop to process subsequent inputs
while (a > 0) {
s += a;
ctr++;
scanf("%d", &a);
return 0;
Copy
Sample Output:
Input a positive integer:
Input next positive integer: 15
Input next positive integer: 25
Input next positive integer: 37
Input next positive integer: 43
Number of positive values entered is 4
Maximum value entered is 43
Minimum value entered is 15
Average value is 30.0000
#include <stdio.h>
int main() {
int i, j, flag, ip = 0;
flag = 1;
// Loop to check if i is divisible by any number other than 1
and itself
if (i % j == 0) {
flag = 0;
// If i is prime, print it
if (flag == 1) {
ip++;
if (ip % 10 == 0) {
printf("\n");
printf("\n");
return 0;
Sample Output:
The prime numbers between 1 and 199 are:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197
C Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 50
int main() {
int i;
char str;
FILE * fptr;
// Open a file for writing
if (fptr == NULL) {
return 0;
srand(time(NULL));
fclose(fptr);
str = fgetc(fptr);
// Print the contents of the file
str = fgetc(fptr);
fclose(fptr);
return 0;
Copy
Sample Output:
50
-0.4215
0.2620
0.3065
-0.0485
-0.2085
-0.2490
-0.2780
0.2905
-0.3120
0.1275
0.4010
0.3060
0.4680
-0.1135
0.0130
-0.0145
-0.1890
-0.3825
0.3790
-0.2370
0.0840
-0.1985
0.2065
0.4445
0.0785
-0.2370
-0.0705
0.3870
-0.4695
0.1525
0.2755
0.3880
-0.3075
-0.1400
-0.3825
-0.0155
-0.1105
-0.1605
-0.4470
0.0780
0.4675
0.2330
-0.3380
0.2135
0.3980
0.1750
0.4780
-0.2915
0.0715
0.3565
C Code:
#include <stdio.h>
int main(){
int count, n;
float x,y;
scanf("%f%d", &x,&n);
y=1.0;
count=1;
while(count<=n)
y=y*x;
count++;
return 0;
Copy
Sample Output:
Input the values of x and n: 256
x=256.000000; n=0;
x to power n=1.000000
68. Write a C program that prints the powers of 2 table for the
powers 0 to 10, both positive and negative.
=======================================
n 2 to power n 2 to power -n
=======================================
0 1 1.000000000000
1 2 0.500000000000
2 4 0.250000000000
3 8 0.125000000000
4 16 0.062500000000
5 32 0.031250000000
6 64 0.015625000000
7 128 0.007812500000
8 256 0.003906250000
9 512 0.001953125000
10 1024 0.000976562500
C Code:
#include<stdio.h>
int main() {
long int p;
int n;
double q;
printf("\n=======================================");
printf("\n=======================================");
p = 1;
// Generate table
if (n == 0)
p = 1;
else
p = p * 2;
q = 1.0 / (double) p;
printf("\n======================================");
return 0;
Copy
Sample Output:
=======================================
n 2 to power n 2 to power -n
=======================================
0 1 1.000000000000
1 2 0.500000000000
2 4 0.250000000000
3 8 0.125000000000
4 16 0.062500000000
5 32 0.031250000000
6 64 0.015625000000
7 128 0.007812500000
8 256 0.003906250000
9 512 0.001953125000
10 1024 0.000976562500
======================================
69. Write a C program to print a binomial coefficient table.
Mx 0 1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------
01
111
2121
31331
414641
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1
9 1 9 36 84 126 126 84 36 9 1
10 1 10 45 120 210 252 210 120 45 10 1
----------------------------------------------------------
C Code:
#include<stdio.h>
#define MAX 10
int main() {
int n, a, bi_nom;
// Print header
printf("Mx ");
printf("\
n----------------------------------------------------------\n");
n = 0;
do {
a = 0, bi_nom = 1;
printf("%2d", n);
while (a <= n) {
if (n == 0 || a == 0)
printf("%4d", bi_nom);
else {
bi_nom = bi_nom * (n - a + 1) / a;
printf("%4d", bi_nom);
a = a + 1;
printf("\n");
n = n + 1;
// Print footer
printf("----------------------------------------------------------");
return 0;
}
Copy
Sample Output:
Mx 0 1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------
0 1
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1
9 1 9 36 84 126 126 84 36 9 1
10 1 10 45 120 210 252 210 120 45 10 1
----------------------------------------------------------
C Code:
#include <stdio.h>
#define N 10
int main() {
char chr;
printf("\n");
// Loop through ASCII values from 65 ('A') to 122 ('z')
continue;
return 0;
Copy
Sample Output:
[65-A] [66-B] [67-C] [68-D] [69-E] [70-F] [71-G] [72-H] [73-I]
[74-J] [75-K] [76-L] [77-M] [78-N] [79-O] [80-P] [81-Q] [82-R]
[83-S] [84-T] [85-U] [86-V] [87-W] [88-X] [89-Y] [90-Z] [97-a]
[98-b] [99-c] [100-d] [101-e] [102-f] [103-g] [104-h] [105-i]
[106-j] [107-k] [108-l] [109-m] [110-n] [111-o] [112-p] [113-q]
[114-r] [115-s] [116-t] [117-u] [118-v] [119-w] [120-x] [121-y]
[122-z]
C Code:
#include<stdio.h>
#define N 10
int main() {
int i;
scanf("%s", str2);
str1[i]=str2[i];
str1[i]='\0';
// Output results
printf("\n");
return 0;
Copy
Sample Output:
Input a string
Original string: w3resource
Number of characters = 10
72. Write a C program to remove any negative sign in front of a
number.
Input a value (negative):
Original value = -253
Absolute value = 253
C Code:
#include<stdio.h>
#define N 10
int abs_val(int);
int main() {
int x, result;
scanf("%d", &x);
result = abs_val(x);
int abs_val(int y) {
if(y < 0)
return(y * -1);
else
return(y);
Copy
Sample Output:
Input a value (negative):
Original value = -253
Absolute value = 253
C Code:
#include<stdio.h>
return n1 % n2 == 0;
}
int main()
scanf("%d", &n1);
scanf("%d", &n2);
if(is_Multiple(n1, n2))
else
return 0;
Copy
Sample Output:
Input the first integer : Input the second integer:
9 is a multiple of 3.
74. Write a C program to display the integer equivalents of
letters (a-z, A-Z).
Sample Output:
List of integer equivalents of letters (a-z, A-Z).
==================================================
97 98 99 100 101 102
103 104 105 106 107 108
109 110 111 112 113 114
115 116 117 118 119 120
121 122 32 65 66 67
68 69 70 71 72 73
74 75 76 77 78 79
80 81 82 83 84 85
86 87 88 89 90
C Code:
#include<stdio.h>
int main()
int n;
// Print header
printf("==================================================\n");
if((n+1) % 6 == 0)
printf("\n");
return 0;
Copy
Sample Output:
List of integer equivalents of letters (a-z, A-Z).
==================================================
97 98 99 100 101 102
103 104 105 106 107 108
109 110 111 112 113 114
115 116 117 118 119 120
121 122 32 65 66 67
68 69 70 71 72 73
74 75 76 77 78 79
80 81 82 83 84 85
86 87 88 89 90
C Code:
#include<stdio.h>
int main()
int n;
scanf("%d", &n);
// Output header
n = n - ((n/1000000)*1000000);
n = n - ((n/100000)*100000);
n = n - ((n/10000)*10000);
n = n - ((n/1000)*1000);
printf("%d ", (n/100));
n = n - ((n/100)*100);
n = n - ((n/10)*10);
printf("%d\n", (n%10));
return 0;
Copy
Sample Output:
Input a seven digit number:
Output: 2 3 4 5 6 7 8
#include<stdio.h>
int main()
int x;
printf("Number\tSquare\tCube\n");
printf("=========================\n");
return 0;
Copy
Sample Output:
Number Square Cube
=========================
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
11 121 1331
12 144 1728
13 169 2197
14 196 2744
15 225 3375
16 256 4096
17 289 4913
18 324 5832
19 361 6859
20 400 8000
Sample Solution:
C Code:
#include<stdio.h>
int main()
{
// Declare variables
while( (int)principal_amt != 0)
// Calculate interest
return 0;
Copy
Sample Output:
Input loan amount (0 to quit): Input interest rate: Input term of
the loan in days: The interest amount is $1000.00
C Code:
#include<stdio.h>
int main()
printf("Predecrementing:\n");
x = 10; // Reset x to 10
// Postdecrementing
printf("Postdecrementing:\n");
return 0;
Copy
Sample Output:
Predecrementing:
x = 10
x-- = 10
x = 9
C Code:
#include<stdio.h>
int main()
printf("x\tx+2\tx+4\tx+6\n\n");
printf("---------------------------\n");
Copy
Sample Output:
x x+2 x+4 x+6
---------------------------
1 3 5 7
4 6 8 10
7 9 11 13
10 12 14 16
13 15 17 19
80. Write a C program that reads the side (side sizes between 1
and 10 ) of a square and prints square using hash (#) character.
Sample Input: 10
Sample Output:
Input the size of the square:
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
Sample Input: 10
Sample Solution:
C Code:
#include<stdio.h>
int main()
Copy
Sample Output:
Input the size of the square:
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
81. Write a C program that reads the side (side sizes between 1
and 10 ) of a square and prints a hollow square using the hash (#)
character.
Sample Input: 10
Sample Output:
Input the size of the square:
##########
# #
# #
# #
# #
# #
# #
# #
# #
##########
Sample Input: 10
Sample Solution:
C Code:
#include <stdio.h>
int main()
// Declare variables
int size, i, j;
scanf("%d", &size);
if (i == 0 || i == size - 1)
else if (j == 0 || j == size - 1)
else
}
return 0; // Indicate successful execution of the program
Copy
Sample Output:
Input the size of the square:
##########
# #
# #
# #
# #
# #
# #
# #
# #
##########
Sample Solution:
C Code:
#include <stdio.h>
int is_Palindrome(int);
int main()
{
int n;
scanf("%d", &n);
if (is_Palindrome(n))
else
return 0;
int is_Palindrome(int n) {
int x = n;
int reverse_num = 0;
reverse_num += x / 10000;
x = x - ((x / 10000) * 10000);
return n == reverse_num;
Copy
Sample Output:
Input a five-digit number: 33333 is a palindrome.
C Code:
#include<stdio.h>
int count_three(int);
int main()
int num;
scanf("%d", &num);
return 0;
while(num> 0) {
Copy
Sample Output:
Input a number: The number of threes in the said number is 2.
Sample Input: 12
15
24
888
Sample Solution:
C Code:
#include <stdio.h>
int main()
scanf("%d", &n);
while (n != 888) {
if (ctr)
Copy
Sample Output:
Input each number on a separate line (888 to exit):
C Code:
#include <stdio.h>
int main()
int i, x;
printf("number numeral\n");
printf("-------------------\n");
if(x == 100) {
x = 0; // Reset x to 0
if(x >= 5) {
if(x % 10 == 9) {
printf("IX"); // Print Roman numeral for 9
x -= 9; // Subtract 9 from x
else {
x -= 5; // Subtract 5 from x
while(x > 0)
if(x % 10 == 4) {
x -= 4; // Subtract 4 from x
else {
x -= 1; // Subtract 1 from x
return 0;
}
Copy
Sample Output:
Decimal Roman
numbers numerals
-------------------
1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VIII
9 IX
10 X
11 XI
12 XII
13 XIII
14 XIV
15 XV
16 XVI
17 XVII
18 XVIII
19 XIX
20 XX
21 XXI
22 XXII
23 XXIII
24 XXIV
25 XXV
26 XXVI
27 XXVII
28 XXVIII
29 XXIX
30 XXX
31 XXXI
32 XXXII
33 XXXIII
34 XXXIV
35 XXXV
36 XXXVI
37 XXXVII
38 XXXVIII
39 XXXIX
40 XL
41 XLI
42 XLII
43 XLIII
44 XLIV
45 XLV
46 XLVI
47 XLVII
48 XLVIII
49 XLIX
50 L
51 LI
52 LII
53 LIII
54 LIV
55 LV
56 LVI
57 LVII
58 LVIII
59 LIX
60 LX
61 LXI
62 LXII
63 LXIII
64 LXIV
65 LXV
66 LXVI
67 LXVII
68 LXVIII
69 LXIX
70 LXX
71 LXXI
72 LXXII
73 LXXIII
74 LXXIV
75 LXXV
76 LXXVI
77 LXXVII
78 LXXVIII
79 LXXIX
80 LXXX
81 LXXXI
82 LXXXII
83 LXXXIII
84 LXXXIV
85 LXXXV
86 LXXXVI
87 LXXXVII
88 LXXXVIII
89 LXXXIX
90 XC
91 XCI
92 XCII
93 XCIII
94 XCIV
95 XCV
96 XCVI
97 XCVII
98 XCVIII
99 XCIX
100 C
86. Write a C program to display the sizes and ranges for each of
C's data types.
Sample Output:
Size of C data types:
Type Bytes
--------------------------------
char 1
int8_t 1
unsigned char 1
uint8_t 1
short 2
int16_t 2
uint16t 2
int 4
unsigned 4
long 8
unsigned long 8
int32_t 4
uint32_t 4
long long 8
int64_t 8
unsigned long long 8
uint64_t 8
float 4
double 8
long double 16
_Bool 1
C Code:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
int main(void) {
// Display title
printf("------------------------------------------------------\
n");
printf("\n");
return 0;
Copy
Sample Output:
Size and Range of C data types:
Type Bytes Range
------------------------------------------------------
char 1 -128 to 127
int8_t 1 -128 to 127
unsigned char 1 0 to 255
uint8_t 1 0 to 255
short 2 -32768 to 32767
int16_t 2 -32768 to 32767
uint16_t 2 0 to 65535
int 4 -2147483648 to 2147483647
unsigned 4 0 to 4294967295
long 4 -2147483648 to 2147483647
unsigned long 4 0 to 4294967295
int32_t 4 -2147483648 to 2147483647
uint32_t 4 0 to 4294967295
long long 8 -9223372036854775808 to
9223372036854775807
int64_t 8 0 to
18446744073709551615
int64_t 8 -9223372036854775808 to
9223372036854775807
uint64_t 8 0 to
18446744073709551615
86. Write a C program to display the sizes and ranges for each of
C's data types.
Sample Output:
Size of C data types:
Type Bytes
--------------------------------
char 1
int8_t 1
unsigned char 1
uint8_t 1
short 2
int16_t 2
uint16t 2
int 4
unsigned 4
long 8
unsigned long 8
int32_t 4
uint32_t 4
long long 8
int64_t 8
unsigned long long 8
uint64_t 8
float 4
double 8
long double 16
_Bool 1
C Code:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
int main(void) {
// Display title
printf("------------------------------------------------------\
n");
printf("\n");
Copy
Sample Output:
Size and Range of C data types:
------------------------------------------------------------
int8_t -128 127
int16_t -32768 32767
int32_t -2147483648 2147483647
int64_t -9223372036854775808 9223372036854775807
uint8_t 0 255
uint16_t 0 65535
uint32_t 0 4294967295
uint64_t 0 18446744073709551615
============================================================
------------------------------------------------------------
float 1.175494e-38 3.402823e+38
double 2.225074e-308 1.797693e+308
long double 3.362103e-4932 1.189731e+4932
C Code:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <float.h>
printf(
"------------------------------------------------------------\n");
printf( "\n" );
printf(
"------------------------------------------------------------\n");
printf( "\n" );
return 0;
Copy
Sample Output:
Ranges for integer data types in C
------------------------------------------------------------
int8_t -128 127
int16_t -32768 32767
int32_t -2147483648 2147483647
int64_t -9223372036854775808 9223372036854775807
uint8_t 0 255
uint16_t 0 65535
uint32_t 0 4294967295
uint64_t 0 18446744073709551615
============================================================
------------------------------------------------------------
float 1.175494e-38 3.402823e+38
double 2.225074e-308 1.797693e+308
long double 3.362103e-4932 1.189731e+4932
C Code:
#include <stdio.h>
printf("|-------------------------------------------------------------
--------------------------------------------|\n" );
printf("|----------------|----------------|-------------|-------------
-|--------------|-------------|-------------|\n" );
char1 = i;
char2 = i+32;
char3 = i+64;
char4 = i+96;
char6 = i+160;
char7 = i+192;
char8 = i+224;
} else {
Copy
Sample Output:
|----------------------------------------------------------------
-----------------------------------------|
|extended ASCII table - excluding control characters
|
| Ch Dec Hex | Ch Dec Hex | Ch Dec Hex | Ch Dec Hex |
Ch Dec Hex | Ch Dec Hex | Ch Dec Hex |
|----------------|----------------|-------------|--------------|-
-------------|-------------|-------------|
| har 32 0x20 | @har 64 0x40 | ` 96 0x60 | � 128 0x80 |
� 160 0xa0 | � 192 0xc0 | � 224 0xe0 |
| !har 33 0x21 | Ahar 65 0x41 | a 97 0x61 | � 129 0x81 |
� 161 0xa1 | � 193 0xc1 | � 225 0xe1 |
| "har 34 0x22 | Bhar 66 0x42 | b 98 0x62 | � 130 0x82 |
� 162 0xa2 | � 194 0xc2 | � 226 0xe2 |
| #har 35 0x23 | Char 67 0x43 | c 99 0x63 | � 131 0x83 |
� 163 0xa3 | � 195 0xc3 | � 227 0xe3 |
| $har 36 0x24 | Dhar 68 0x44 | d 100 0x64 | � 132 0x84 |
� 164 0xa4 | � 196 0xc4 | � 228 0xe4 |
| %har 37 0x25 | Ehar 69 0x45 | e 101 0x65 | � 133 0x85 |
� 165 0xa5 | � 197 0xc5 | � 229 0xe5 |
| &har 38 0x26 | Fhar 70 0x46 | f 102 0x66 | � 134 0x86 |
� 166 0xa6 | � 198 0xc6 | � 230 0xe6 |
| 'har 39 0x27 | Ghar 71 0x47 | g 103 0x67 | � 135 0x87 |
� 167 0xa7 | � 199 0xc7 | � 231 0xe7 |
| (har 40 0x28 | Hhar 72 0x48 | h 104 0x68 | � 136 0x88 |
� 168 0xa8 | � 200 0xc8 | � 232 0xe8 |
| )har 41 0x29 | Ihar 73 0x49 | i 105 0x69 | � 137 0x89 |
� 169 0xa9 | � 201 0xc9 | � 233 0xe9 |
| *har 42 0x2a | Jhar 74 0x4a | j 106 0x6a | � 138 0x8a |
� 170 0xaa | � 202 0xca | � 234 0xea |
| +har 43 0x2b | Khar 75 0x4b | k 107 0x6b | � 139 0x8b |
� 171 0xab | � 203 0xcb | � 235 0xeb |
| ,har 44 0x2c | Lhar 76 0x4c | l 108 0x6c | � 140 0x8c |
� 172 0xac | � 204 0xcc | � 236 0xec |
| -har 45 0x2d | Mhar 77 0x4d | m 109 0x6d | � 141 0x8d |
� 173 0xad | � 205 0xcd | � 237 0xed |
| .har 46 0x2e | Nhar 78 0x4e | n 110 0x6e | � 142 0x8e |
� 174 0xae | � 206 0xce | � 238 0xee |
| /har 47 0x2f | Ohar 79 0x4f | o 111 0x6f | � 143 0x8f |
� 175 0xaf | � 207 0xcf | � 239 0xef |
| 0har 48 0x30 | Phar 80 0x50 | p 112 0x70 | � 144 0x90 |
� 176 0xb0 | � 208 0xd0 | � 240 0xf0 |
| 1har 49 0x31 | Qhar 81 0x51 | q 113 0x71 | � 145 0x91 |
� 177 0xb1 | � 209 0xd1 | � 241 0xf1 |
| 2har 50 0x32 | Rhar 82 0x52 | r 114 0x72 | � 146 0x92 |
� 178 0xb2 | � 210 0xd2 | � 242 0xf2 |
| 3har 51 0x33 | Shar 83 0x53 | s 115 0x73 | � 147 0x93 |
� 179 0xb3 | � 211 0xd3 | � 243 0xf3 |
| 4har 52 0x34 | Thar 84 0x54 | t 116 0x74 | � 148 0x94 |
� 180 0xb4 | � 212 0xd4 | � 244 0xf4 |
| 5har 53 0x35 | Uhar 85 0x55 | u 117 0x75 | � 149 0x95 |
� 181 0xb5 | � 213 0xd5 | � 245 0xf5 |
| 6har 54 0x36 | Vhar 86 0x56 | v 118 0x76 | � 150 0x96 |
� 182 0xb6 | � 214 0xd6 | � 246 0xf6 |
| 7har 55 0x37 | Whar 87 0x57 | w 119 0x77 | � 151 0x97 |
� 183 0xb7 | � 215 0xd7 | � 247 0xf7 |
| 8har 56 0x38 | Xhar 88 0x58 | x 120 0x78 | � 152 0x98 |
� 184 0xb8 | � 216 0xd8 | � 248 0xf8 |
| 9har 57 0x39 | Yhar 89 0x59 | y 121 0x79 | � 153 0x99 |
� 185 0xb9 | � 217 0xd9 | � 249 0xf9 |
| :har 58 0x3a | Zhar 90 0x5a | z 122 0x7a | � 154 0x9a |
� 186 0xba | � 218 0xda | � 250 0xfa |
| ;har 59 0x3b | [har 91 0x5b | { 123 0x7b | � 155 0x9b |
� 187 0xbb | � 219 0xdb | � 251 0xfb |
| <har 60 0x3c | \har 92 0x5c | | 124 0x7c | � 156 0x9c |
� 188 0xbc | � 220 0xdc | � 252 0xfc |
| =har 61 0x3d | ]har 93 0x5d | } 125 0x7d | � 157 0x9d |
� 189 0xbd | � 221 0xdd | � 253 0xfd |
| >har 62 0x3e | ^har 94 0x5e | ~ 126 0x7e | � 158 0x9e |
� 190 0xbe | � 222 0xde | � 254 0xfe |
| ?har 63 0x3f | _har 95 0x5f |DEL 127 0x7f | � 159 0x9f |
� 191 0xbf | � 223 0xdf | � 255 0xff |
C Code:
#include <stdio.h>
int main()
// Declare variables
long long x, y, z;
printf("Input x, y, z:\n");
Copy
Sample Output:
Input x,y,x:
Result: 140733606875472
C Code:
#include<stdio.h>
base *= 10;
int i;
int flag;
flag = 0;
if(n % i == 0){
break;
int main(){
int x, y, temp = 0;
temp = compute(x);
prime(temp);
Copy
Sample Output:
Input two numbers (separated by a space):
List of prime palindromes:
0
1
C Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
angle = -angle;
if ( m < 10 )
else
Copy
Sample Output:
Input hour(h) and minute(m) (separated by a space):
3 0
At 3:00 the angle is 90.0 degrees.
Input hour(h) and minute(m) (separated by a space):
6 15
The angle is 90.0 degrees at 6:15.
Input hour(h) and minute(m) (separated by a space):
12 0
At 12:00 the angle is 0.0 degrees.
92. Write a C program to find the last non-zero digit of the
factorial of a given positive integer.
For example for 5!, the output will be "2" because 5! = 120, and 2
is the last nonzero digit of 120
Sample Output:
Input a positive number:
The last non-zero digit of the said factorial:
0
C Code:
#include <stdio.h>
#include <string.h>
int j;
char c, tmp;
if(i[0] < 5)
c = i[0];
(*len)--;
c = tmp;
else
c = 0;
c = tmp;
char ans, c, d;
if(len == 1 &&i[0] < 5)
return ftr[(int)i[0]];
else
comp(i, &len);
if(ans == 2 || ans == 6)
ans += 10;
ans /= 2;
int main()
char chr[1002];
int len, i;
char c;
scanf("%s", chr);
len = strlen(chr);
chr[i] -= '0';
c = fact(chr, len);
putchar(c + '0');
putchar(10);
return 0;
Copy
Sample Output:
Input a positive number:
The last non-zero digit of the said factorial:
0
C Code:
#include <stdio.h>
int main() {
primes[num_of_primes++] = 2;
int flag = 1;
flag = 0;
break;
int N, num;
scanf("%d", &num);
int flag = 0;
if(num % primes[j] == 0) {
num /= primes[j];
flag = 1;
break;
else
return 0;
if(num != 2 &&num % 2 == 0)
return 0;
if(num % factor == 0)
return 0;
return 1;
Copy
Sample Output:
It is not a Nearly prime number.
94. Write a C program to calculate body mass index and display
the grade.
Sample Output:
Input the weight: 65
Input the height: 5.6
BMI = 2.072704
Grade: Under
C Code:
#include <stdio.h>
int main(void) {
scanf("%d", &w);
scanf("%f", &h);
BMI(w, h);
}
printf("\nGrade: ");
temp< 18.5 ? printf("Under ") : temp < 25 ? printf("Normal ") : temp <
30 ? printf("Over ") : temp < 40 ? printf("Obese ") : printf("Error");
Copy
Sample Output:
Input the weight: 65
Input the height: 5.6
BMI = 2.072704
Grade: Under
Fahrenheit to Celsius
---------------------
Fahrenheit Celsius
0.0 -17.8
10.0 -12.2
20.0 -6.7
30.0 -1.1
40.0 4.4
50.0 10.0
...
120.0 48.9
130.0 54.4
140.0 60.0
150.0 65.6
C Code:
#include <stdio.h>
int main() {
start_temp = 0;
end_temp = 150;
STEP = 10;
printf("Fahrenheit to Celsius");
printf("\n---------------------\n");
printf("Fahrenheit Celsius\n");
start_temp = 0;
end_temp = 150;
STEP = 10;
printf("\n\nCelsius to Fahrenheit\n");
printf("---------------------\n");
printf("Celsius Fahrenheit\n");
Copy
Sample Output:
Celsius to Fahrenheit
---------------------
Celsius Fahrenheit
0.0 32.0
10.0 50.0
20.0 68.0
30.0 86.0
40.0 104.0
50.0 122.0
60.0 140.0
70.0 158.0
80.0 176.0
90.0 194.0
100.0 212.0
110.0 230.0
120.0 248.0
130.0 266.0
140.0 284.0
150.0 302.0
Fahrenheit to Celsius
---------------------
Fahrenheit Celsius
0.0 -17.8
10.0 -12.2
20.0 -6.7
30.0 -1.1
40.0 4.4
50.0 10.0
60.0 15.6
70.0 21.1
80.0 26.7
90.0 32.2
100.0 37.8
110.0 43.3
120.0 48.9
130.0 54.4
140.0 60.0
150.0 65.6
#include <stdio.h>
int main() {
if (c == ' ') {
if (c == '\t') {
if (c == '\n') {
}
}
Copy
Sample Output:
Number of blanks, tabs, and newlines:
Input few words/tab/newlines
The quick
brown fox jumps
over the lazy dog
^Z
blank=7,tab=2,newline=3
Number of Characters = 44
Number of words = 9
Number of lines = 1
C Code:
#include <stdio.h>
int main() {
} else if (c == '\n') {
} else {
if (flag == 0) {
}
// Print the counts of characters, words, and lines
Copy
Sample Output:
Input a string and get number of characters, words and lines:
The quick brown fox jumps over the lazy dog
^Z
Number of Characters = 44
Number of words = 9
Number of lines = 1
98. Write a C program that accepts some text from the user and
prints each word of that text on a separate line.
Sample Output:
Input some text:
The quick brown fox jumps over the lazy dog
The
quick
brown
fox
jumps
over
the
lazy
dog
C Code:
#include <stdio.h>
int main() {
long nc = 0; // Variable to count characters
} else {
if (flag == 0) {
}
if (flag == 0 && last == 0) {
} else {
Copy
Sample Output:
Input some text:
The quick brown fox jumps over the lazy dog
The
quick
brown
fox
jumps
over
the
lazy
dog
99. Write a C program that takes some integer values from the
user and prints a histogram.
Sample Output:
Input number of histogram bar (Maximum 10):
4
Input the values between 0 and 10 (separated by space):
9
7
4
3
Histogram:
#########
#######
####
###
C Code:
#include <stdio.h>
int main() {
int i, j;
scanf("%d", &inputValue);
int hist[inputValue];
if (inputValue<=10)
hist[i] = hist_value;
hist_value=0;
if ( hist[j] == i){
results[i]++;
printf("\n");
print_Histogram(hist, inputValue);
return 0;
printf("\nHistogram:\n");
int i, j;
// Loop through the histogram bars and print '#' for each
occurrence
printf("#");
printf("\n");
Copy
Sample Output:
Input number of histogram bar (Maximum 10):
4
Input the values between 0 and 10 (separated by space):
9
7
4
3
Histogram:
#########
#######
####
###
Currency Coins:
.50 number of Coin(s): 1
.25 number of Coin(s): 1
C Code:
#include <stdio.h>
#include <math.h>
int main() {
double amt;
scanf("%lf", &amt);
amt -= int_amt;
printf("\nCurrency Notes:");
int_amt -= 50;
if (int_amt/20 > 0)
if (int_amt/10 > 0)
printf("\n10 number of Note(s): %d", int_amt / 10);
if (int_amt/5 > 0)
int_amt -= (int_amt / 5) * 5;
if (int_amt > 0)
int_amt -= (int_amt / 2) * 2;
if (int_amt > 0)
printf("\n\nCurrency Coins:");
// Check and display 50 paise coins
frac_amt -= 50;
if (frac_amt/25 > 0)
if (frac_amt/10 > 0)
if (frac_amt/5 > 0)
frac_amt -= (frac_amt / 5) * 5;
if (frac_amt > 0)
return 0;
Copy
Sample Output:
Input the currency value (floating point with two decimal
places):
10387.75
Currency Notes:
100 number of Note(s): 103
50 number of Note(s): 1
20 number of Note(s): 1
10 number of Note(s): 1
5 number of Note(s): 1
2 number of Note(s): 1
Currency Coins:
.50 number of Coin(s): 1
.25 number of Coin(s): 1
101. There are three given ranges. Write a C program that reads
a floating-point number and finds the range where it belongs from
four given ranges.
Sample Output:
Input a number: 87
Range (80,100]
C Code:
#include <stdio.h>
int main ()
float x = 0;
scanf("%f", &x);
// Check the range of the input number and print the corresponding
message
printf("Range [0,30]\n");
printf("Range (30,50]\n");
printf("Range (50,80]\n");
printf("Range (80,100]\n");
else
Copy
Sample Output:
Input a number: 87
Range (80,100]
102. Write a C program that reads three integers and sorts the
numbers in ascending order. Print the original numbers and the
sorted numbers.
Sample Output:
Input 3 integers: 17
-5
25
---------------------------
Original numbers: 17, -5, 25
Sorted numbers: -5, 17, 25
C Code:
#include <stdio.h>
#include <math.h>
int x, y, z;
printf("\n---------------------------\n");
else{
else{
else{
else{
else{
if (x == y && y == z){
else{
Copy
Sample Output:
Input 3 integers: 17
-5
25
---------------------------
Original numbers: 17, -5, 25
Sorted numbers: -5, 17, 25
103. Write a C program that takes two integers and tests
whether they are multiplied or not.
In science, a multiple is the product of any quantity and an
integer. In other words, for the quantities a and b, we say that b
is a multiple of a if b = na for some integer n, which is called the
multiplier. If a is not zero, this is equivalent to saying that b/a is
an integer.
Sample Output:
Input two integers:
3
9
Multiplies
C Code:
#include <stdio.h>
int main () {
if (x > y){
// Calculate the remainder when x is divided by y
multi = x % y;
if ( multi == 0){
printf("Multiplies\n");
else{
printf("Not Multiplies\n");
else{
multi = y % x;
if (multi == 0){
printf("Multiplies\n");
else{
printf("Not Multiplies\n");
Copy
Sample Output:
Input two integers:
3
9
Multiplies
104. Write a C program that reads the item's price and creates a
revised price for the item, based on the item price table.
Sample Output:
Input the item price:525
New Item price: 582.75
Increased price: 57.75
Increase Percentage: 11%
C Code:
#include <stdio.h>
int main ()
scanf("%f", &price);
// Check the range of the item price and calculate increased price
and percentage accordingly
else{
else{
else{
else{
Copy
Sample Output:
Input the item price:525
New Item price: 582.75
Increased price: 57.75
Increase Percentage: 11%
C Code:
#include <stdio.h>
int main () {
printf("Input 7 numbers(int/float):\n");
// Read a number
scanf("%f", &x);
if (x > 0){
if (x < 0){
}
}
p_avg = temp_p/p_ctr;
n_avg = temp_n/n_ctr;
Copy
Sample Output:
Input 7 numbers(int/float):
25
35.75
15
-3.5
40
35
16
Input 7 integers:
10
12
15
-15
26
35
17
C Code:
#include <stdio.h>
int main ()
// Read an integer
scanf("%d", &x);
if (x > 0){
if (x < 0){
if (x % 2 == 0){
if (x % 2 != 0){
ctr_odd++; // Increment odd counter
Copy
Sample Output:
Input 7 integers:
10
12
15
-15
26
35
17
107. Write a C program that prints ten consecutive odd and even
numbers after accepting an integer.
Sample Output:
Input an integer number:
15
C Code:
#include <stdio.h>
int main () {
int a, i, ctr = 0;
scanf("%d", &a);
if (i % 2 != 0){
ctr++;
}
// Reset counter for even numbers
ctr = 0;
if (i % 2 == 0){
ctr++;
Copy
Sample Output:
Input an integer number:
15
C Code:
#include <stdio.h>
int main () {
// Declare variables for input, counters, and sum of odd and even
numbers
scanf("%d", &a);
scanf("%d", &b);
if (b > a)
if (i % 2 != 0){
sum_odd = sum_odd + i;
printf("\n%d", sum_odd);
// Reset counter
ctr = 0;
if (i % 2 == 0){
sum_even = sum_even + i;
printf("\n%d", sum_even);
}
}
Copy
Sample Output:
Input the first integer number:
25
Input the second integer number (greater than first integer):
45
Sum of all odd values between 25 and 45:
385
Sum of all even values between 25 and 45:
350
109. Write a C program to find and print the square of each even
and odd value between 1 and a given number (4 < n < 101).
Sample Output:
Input a number(integer): 15
C Code:
#include <stdio.h>
#include <math.h>
int main () {
int x, cont = 0, i;
scanf("%d", &x);
if (i % 2 == 0){
if (i % 2 != 0){
cont = pow(i, 2);
Copy
Sample Output:
Input a number(integer): 15
C Code:
#include <stdio.h>
int main () {
int b;
scanf("%d", &b);
printf("Number is positive-even\n");
else{
printf("Number is negative-even'\n");
else{
else{
printf("Number is negative-odd\n");
else{
printf("Zero\n");
Copy
Sample Output:
Input a number (integer):
12
Number is positive-even
C Code:
#include <stdio.h>
int main () {
// Declare variables
int x, i, y;
scanf("%d", &x);
if (i % x == 3){
printf("%d\n", i);
}
return 0; // End of program
Copy
Sample Output:
Input a number (integer):
65
112. Write a C program that reads seven integer values from the
user and finds the highest value and its position.
Sample Output:
Input 6 numbers (integer values):
15
20
25
17
-8
35
Maximum value: 35
Position: 6
C Code:
#include <stdio.h>
int main () {
// Declare variables
scanf("%d", &x);
if (n >= temp_num){
}
Copy
Sample Output:
Input 6 numbers (integer values):
15
20
25
17
-8
35
Maximum value: 35
Position: 6
C Code:
#include <stdio.h>
int main ()
int a, b;
Copy
Sample Output:
a=1 b=100
a=6 b=90
a=11 b=80
a=16 b=70
a=21 b=60
a=26 b=50
a=31 b=40
a=36 b=30
a=41 b=20
a=46 b=10
a=51 b=0
C Code:
#include <stdio.h>
int main () {
int y, i, z;
// Read two integer values from user and store them in 'm' and 'n'
if (m > n) {
// Loop to find and sum all even numbers between 'n' and 'm'
if (l % 2 == 0){
else {
// Loop to find and sum all even numbers between 'm' and 'n'
Copy
Sample Output:
Input two numbers (integer values):
25
45
Sample Output:
Input two pairs values (integer values):
14
25
Sequence from the lowest to highest number:
14 15 16 17 18 19 20 21 22 23 24 25
Average value of the said sequence
19.50
Sample Output:
Input two pairs values (integer values):
35
13
C Code:
#include <stdio.h>
int main () {
int p, x = 1, y = 1, i = 0, temp = 0;
float sum_val = 0;
// Read two integer values from user and store them in 'x' and 'y'
temp = x;
x = y;
y = temp;
p++;
Copy
Sample Output:
Input two pairs values (integer values):
14
25
Sequence from the lowest to highest number:
14 15 16 17 18 19 20 21 22 23 24 25
Average value of the said sequence
19.50
Sample Output:
Input two pairs values (integer values):
35
13
Sample Output:
Input two pairs values (integer values):
12
35
Ascending order
Sample Output:
Input two pairs values (integer values):
65
25
Descending order
C Code:
#include <stdio.h>
int main () {
int a, b;
// Prompt user for input
// Read two integer values from user and store them in 'a' and 'b'
if (a != b) {
if (b > a) {
else {
Copy
Sample Output:
Input two pairs values (integer values):
12
35
Ascending order
Sample Output:
Input two pairs values (integer values):
65
25
Descending order
117. Write a C program that reads two integers and divides the
first number by second, print the result of this division with two
digits after the decimal point and prints “Division not possible..!”
if the division is not possible.
Sample Output:
Input two integer values:
75
5
Result: 15.00
C Code:
#include <stdio.h>
int main () {
int n, x, y, i;
float result = 0;
// Read two integer values from user and store them in 'x' and 'y'
if (y == 0) {
else {
Copy
Sample Output:
Input two integer values:
75
5
Result: 15.00
Sample Output:
Input five subject marks(0-100):
75
84
56
98
68
Average marks = 76.20
C Code:
#include <stdio.h>
int main () {
int i = 0, subject = 0;
while (subject != 5) {
scanf("%f", &marks);
else {
Copy
Sample Output:
Input five subject marks(0-100):
75
84
56
98
68
Average marks = 76.20
Sample Output:
Input two numbers(integer):
25
5
Sum of all numbers between said numbers (inclusive) not divisible
by 7:
273
Sample Output:
Input two numbers(integer):
6
36
Sum of all numbers between said numbers (inclusive) not divisible
by 7:
546
C Code:
#include <stdio.h>
int main () {
// Read two integer values from user and store them in 'a' and 'b'
if (b < a) {
temp = a;
a = b;
b = temp;
if (i % 7 != 0) {
printf("%d\n", sum_nums);
Copy
Sample Output:
Input two numbers(integer):
25
5
Sum of all numbers between said numbers (inclusive) not divisible
by 7:
273
Sample Output:
Input two numbers(integer):
6
36
Sum of all numbers between said numbers (inclusive) not divisible
by 7:
546
Sample Output:
Input a number(integer):
25
Sequence:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
C Code:
#include <stdio.h>
int main () {
int n, i;
printf("\nInput a number(integer):\n");
scanf("%d", &n);
if (n > 0) {
printf("Sequence:\n");
Copy
Sample Output:
Input a number(integer):
25
Sequence:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
121. Write a C program that reads an integer and finds all the
divisors of the said integer.
Sample Output:
Input a number (integer value):
35
C Code:
#include <stdio.h>
int main () {
int i, n;
scanf("%d", &n);
// Print a message indicating what the program will do
if (n % i == 0) {
Copy
Sample Output:
Input a number (integer value):
35
Sample Output:
Input two integes (m, n):
20
60
C Code:
#include <stdio.h>
int main () {
int m, n, i, j, k, sum_even_nums = 0;
// Loop to find and sum 'n' even numbers starting from 'm'
if (j % 2 == 0) {
printf("\n%d", sum_even_nums);
Copy
Sample Output:
Input two integes (m, n):
20
60
C Code:
#include <stdio.h>
int main () {
int m, n, i, j, k, sum_even_nums = 0;
// Loop to find and sum 'n' even numbers starting from 'm'
if (j % 2 == 0) {
printf("\n%d", sum_even_nums);
Copy
Sample Output:
Input two integes (m, n):
20
60
Sample Output:
Input two integes (m, n):
65
5
Sample Output:
Input 7 array elements:
15
12
-7
25
0
27
53
Array elements:
array_nums[0] = 15
array_nums[1] = 12
array_nums[2] = 1
array_nums[3] = 25
array_nums[4] = 1
array_nums[5] = 27
array_nums[6] = 53
C Code:
#include <stdio.h>
int main () {
int array_nums[7], i, n;
// Loop to read 7 integer values from the user and store them in
the array
scanf("%d", &n);
array_nums[i] = n;
printf("\nArray elements:\n");
if (array_nums[i] <= 0) {
Copy
Sample Output:
Input 7 array elements:
15
12
-7
25
0
27
53
Array elements:
array_nums[0] = 15
array_nums[1] = 12
array_nums[2] = 1
array_nums[3] = 25
array_nums[4] = 1
array_nums[5] = 27
array_nums[6] = 53
125. Write a C program that reads an array of integers (length 7),
and replaces the first element of the array by a given number and
replaces each subsequent position of the array by the double
value of the previous.
Sample Output:
Input the first element of the array:
5
Array elements:
array_nums[0] = 5
array_nums[1] = 10
array_nums[2] = 20
array_nums[3] = 40
array_nums[4] = 80
array_nums[5] = 160
array_nums[6] = 320
C Code:
#include <stdio.h>
int main () {
int array_nums[7], i, x, k;
scanf("%d", &x);
printf("\nArray elements:\n");
Copy
Sample Output:
Input the first element of the array:
5
Array elements:
array_nums[0] = 5
array_nums[1] = 10
array_nums[2] = 20
array_nums[3] = 40
array_nums[4] = 80
array_nums[5] = 160
array_nums[6] = 320
Sample Output:
Input 7 array elements:
15
23
37
65
20
-7
65
C Code:
#include <stdio.h>
int main () {
float n, array_nums[7];
int i;
// Prompt user for input
// Loop to read 7 float values from the user and store them in the
array
scanf("%f", &n);
array_nums[i] = n;
if (array_nums[i] <= 0) {
Sample Output:
Input 7 array elements:
15
23
37
65
20
-7
65
Sample Output:
Input 8 array elements:
25
35
17
-5
29
45
60
65
Modified array:
array_nums[0] = 65
array_nums[1] = 60
array_nums[2] = 45
array_nums[3] = 29
array_nums[4] = -5
array_nums[5] = 17
array_nums[6] = 35
array_nums[7] = 25
C Code:
#include <stdio.h>
int main () {
// Loop to read 8 short values from the user and store them in the
array
scanf("%hd", &n);
array_nums[i] = n;
// Loop to swap elements from the first half of the array with the
second half
temp1 = array_nums[i];
temp2 = array_nums[j];
array_nums[i] = temp2;
array_nums[j] = temp1;
printf("\nModified array:\n");
Copy
Sample Output:
Input 8 array elements:
25
35
17
-5
29
45
60
65
Modified array:
array_nums[0] = 65
array_nums[1] = 60
array_nums[2] = 45
array_nums[3] = 29
array_nums[4] = -5
array_nums[5] = 17
array_nums[6] = 35
array_nums[7] = 25
Sample Output:
Input an integer (2-10)
8
array_nums[0] = 0
array_nums[1] = 1
array_nums[2] = 2
array_nums[3] = 3
array_nums[4] = 4
array_nums[5] = 5
array_nums[6] = 6
array_nums[7] = 7
array_nums[8] = 0
array_nums[9] = 1
C Code:
#include <stdio.h>
int main ()
int n, i, array_nums[10], k;
scanf("%d", &n);
k = 0;
array_nums[i] = k;
k++;
if (k == n)
k = 0;
}
}
Copy
Sample Output:
Input an integer (2-10)
8
array_nums[0] = 0
array_nums[1] = 1
array_nums[2] = 2
array_nums[3] = 3
array_nums[4] = 4
array_nums[5] = 5
array_nums[6] = 6
array_nums[7] = 7
array_nums[8] = 0
array_nums[9] = 1
Sample Output:
Input an integer (2-10)
8
array_nums[0] = 0
array_nums[1] = 1
array_nums[2] = 2
array_nums[3] = 3
array_nums[4] = 4
array_nums[5] = 5
array_nums[6] = 6
array_nums[7] = 7
array_nums[8] = 0
array_nums[9] = 1
C Code:
#include <stdio.h>
int main ()
int i;
double array_nums[10];
double n;
printf("Input a number:\n");
scanf("%lf", &n);
// Initialize the first element of the array with the input value
array_nums[0] = n;
printf("\nArray elements:\n");
Copy
Sample Output:
Input a number:
35
Array elements:
array_nums[0] = 35.0000
array_nums[1] = 11.6667
array_nums[2] = 3.8889
array_nums[3] = 1.2963
array_nums[4] = 0.4321
array_nums[5] = 0.1440
array_nums[6] = 0.0480
array_nums[7] = 0.0160
array_nums[8] = 0.0053
array_nums[9] = 0.0018
Sample Output:
Input a number:
35
Array elements:
array_nums[0] = 35.0000
array_nums[1] = 11.6667
array_nums[2] = 3.8889
array_nums[3] = 1.2963
array_nums[4] = 0.4321
array_nums[5] = 0.1440
array_nums[6] = 0.0480
array_nums[7] = 0.0160
array_nums[8] = 0.0053
array_nums[9] = 0.0018
C Code:
#include <stdio.h>
int main ()
int array_size, i, x, z;
scanf("%d", &array_size);
int vetor[array_size];
scanf("%d", &z);
min_val = vetor[0];
position = 0;
// Loop to find the smallest value and its position within the array
Sample Output:
Input the array size:
5
Smallest Value: -5
Position within array: 2
Sample Output:
Input the first string:
abcdef
Input the second string:
ef
Is second string present in the last part of the first string?
Present!
C Code:
#include <stdio.h>
#include <string.h>
int main() {
scanf("%s", num1);
scanf("%s", num2);
num1_len = strlen(num1);
num2_len = strlen(num2);
printf("Present!\n");
else
printf("Not Present!\n");
printf("Not Present!\n");
else
printf("Not Present!\n");
Copy
Sample Output:
Input the first string:
abcdef
Input the second string:
ef
Is second string present in the last part of the first string?
Present!
Sample Output:
Input heights(integer values) of the top eight buildings:
25
15
45
22
35
18
95
65
C Code:
#include<stdio.h>
int main(){
scanf("%d", &heights[i]);
max_heights = i;
max_heights = j;
h = heights[max_heights];
heights[max_heights] = heights[i];
heights[i] = h;
Copy
Sample Output:
Input heights(integer values) of the top eight buildings:
25
15
45
22
35
18
95
65
Sample Output:
Input two integer values:
68
75
#include <stdio.h>
int main()
while (sum_val != 0)
if (sum_val > 0)
Copy
Sample Output:
Input two integer values:
68
75
Sample Output:
Input the three sides of a trainagel:
12
11
13
It is not a right angle triangle!
Input:
Integers separated by a single space.
1 <= length of the side <= 1,000
Sample Solution:
C Code:
#include<stdio.h>
int main()
int x, y, z;
else
}
return 0; // End of the program
Copy
Sample Output:
Input the three sides of a trainagel:
12
11
13
It is not a right angle triangle!
Sample Output:
Input a number:
5
a + b + c + d = n
0, 0, 0, 5
0, 0, 1, 4
....
4, 0, 1, 0
4, 1, 0, 0
5, 0, 0, 0
Input:
n (1 <= n <= 50)
Sample Solution:
C Code:
#include<stdio.h>
int main() {
int i, j, k, l, n;
printf("Input a number:\n");
scanf("%d", &n);
printf("\na + b + c + d = n");
int count = 0;
if (i + j + k + l == n) {
count++;
}
}
Copy
Sample Output:
Input a number:
5
a + b + c + d = n
0, 0, 0, 5
0, 0, 1, 4
0, 0, 2, 3
0, 0, 3, 2
0, 0, 4, 1
0, 0, 5, 0
0, 1, 0, 4
0, 1, 1, 3
0, 1, 2, 2
0, 1, 3, 1
0, 1, 4, 0
0, 2, 0, 3
0, 2, 1, 2
0, 2, 2, 1
0, 2, 3, 0
0, 3, 0, 2
0, 3, 1, 1
0, 3, 2, 0
0, 4, 0, 1
0, 4, 1, 0
0, 5, 0, 0
1, 0, 0, 4
1, 0, 1, 3
1, 0, 2, 2
1, 0, 3, 1
1, 0, 4, 0
1, 1, 0, 3
1, 1, 1, 2
1, 1, 2, 1
1, 1, 3, 0
1, 2, 0, 2
1, 2, 1, 1
1, 2, 2, 0
1, 3, 0, 1
1, 3, 1, 0
1, 4, 0, 0
2, 0, 0, 3
2, 0, 1, 2
2, 0, 2, 1
2, 0, 3, 0
2, 1, 0, 2
2, 1, 1, 1
2, 1, 2, 0
2, 2, 0, 1
2, 2, 1, 0
2, 3, 0, 0
3, 0, 0, 2
3, 0, 1, 1
3, 0, 2, 0
3, 1, 0, 1
3, 1, 1, 0
3, 2, 0, 0
4, 0, 0, 1
4, 0, 1, 0
4, 1, 0, 0
5, 0, 0, 0
136. Write a C program to find prime numbers that are less than
or equal to a given integer.
Input:
n (1 <= n <= 999,999)
Sample Output:
Input a number:
123
Number of prime numbers which are less than or equal to 123
30
Input:
n (1 <= n <= 999,999)
Sample Solution:
C Code:
#include<stdio.h>
int prime[MAX_N];
int main() {
int p = 0, i, j, n;
printf("Input a number:\n");
scanf("%d", &n);
is_prime[i] = 1;
if (is_prime[i]) {
for (j = 2 * i; j <= n; j += i)
printf("\n%d", p);
Copy
Sample Output:
Input a number:
123
Number of prime numbers which are less than or equal to 123
30
Sample Output:
Input three points to form a triangle:
x1 y1 z1
Input:
x1,y1,x2,y2,x3,y3,xp,yp separated by a single space
Sample Solution:
C Code:
#include <stdio.h>
return X1 * Y2 - X2 * Y2;
int main() {
scanf("%lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2],
&y[2]);
if (((cop1 > 0.0) && (cop2 > 0.0) && (cop3 > 0.0)) ||
((cop1 < 0.0) && (cop2 < 0.0) && (cop3 < 0.0))) {
} else {
Copy
Sample Output:
Input three points to form a triangle:
x1 y1 z1
Sample Output:
Input P(x1,y1):
5
7
Input P(x2,y2):
3
6
Input P(x3,y3):
8
9
Input P(x4,y4):
5
6
Input:
−100 <= x1, y1, x2, y2, x3, y3, x4, y4 <= 100
Each value is a real number with at most 5 digits after the
decimal point.
Sample Solution:
C Code:
#include <stdio.h>
main() {
// Variable declarations
int i, n;
printf("Input P(x1,y1):\n");
printf("\nInput P(x2,y2):\n");
printf("\nInput P(x3,y3):\n");
printf("\nInput P(x4,y4):\n");
else if (((y1 - y2) / (x1 - x2) - (y3 - y4) / (x3 - x4)) == 0.0)
else
Copy
Sample Output:
Input P(x1,y1):
5
7
Input P(x2,y2):
3
6
Input P(x3,y3):
8
9
Input P(x4,y4):
5
6
Sample Output:
Input number of terms in the sequence:
5
You can assume that 1 <= n <= 500 and -10000 <= ai <= 10000.
A contiguous subsequence of a list S is a subsequence made up
of consecutive elements of S.
For instance, if S is
5, 15, −30, 10, −5, 40, 10,
then 15, −30, 10 is a contiguous subsequence but 5, 15, 40 is not.
Give a linear-time algorithm for the following task:
• Input: A list of numbers a1, a2, . . . , an
• Output: The contiguous subsequence of maximum sum. (Note
that a subsequence of length zero has sum zero.)
For the preceding example, the answer would be 10, −5, 40, 10,
with a sum of 55
Ref: https://bit.ly/2IGGI3f
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int n;
long a[5000];
int i, j;
scanf("%d", &n);
// Getting the terms of the sequence from the user
scanf("%ld", &(a[i]));
max = a[0];
tmp = 0;
tmp += a[j];
max = tmp;
tmp = 0;
printf("%lld\n", max);
}
Sample Output:
Input number of terms in the sequence:
5
Sample Output:
C Code:
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void) {
int in;
int i;
max_val = nums[i];
if (max_val == nums[i])
printf("%d\n", i);
}
Copy
Sample Output:
Sample Output:
Input the number:
3
C Code:
#include<stdio.h>
int i, result = 0;
if (n == 1) {
return 1;
} else {
return 0;
int main() {
int n, s;
scanf("%d", &n);
scanf("%d", &s);
if (n != 0 && s != 0) {
return 0;
Copy
Sample Output:
Input the number:
3
142. Write a C program that reads the two adjoining sides and
the diagonal of a parallelogram and checks whether the
parallelogram is a rectangle or a rhombus.
Input:
Two adjoined sides and the diagonal.
1 <= ai, bi, ci <= 1000, ai + bi > ci
Sample Output:
Input two adjoined sides of the parallelogram:
3
4
This is a rectangle.
Sample Output:
Input two adjoined sides of the parallelogram:
5
5
This is a rhombus.
According to Wikipedia-
parallelograms: In Euclidean geometry, a parallelogram is a
simple (non-self-intersecting) quadrilateral with two pairs of
parallel sides. The opposite or facing sides of a parallelogram are
of equal length and the opposite angles of a parallelogram are of
equal measure.
rectangles: In Euclidean plane geometry, a rectangle is a
quadrilateral with four right angles. It can also be defined as an
equiangular quadrilateral, since equiangular means that all of its
angles are equal (360°/4 = 90°). It can also be defined as a
parallelogram containing a right angle.
rhombus: In plane Euclidean geometry, a rhombus (plural rhombi
or rhombuses) is a simple (non-self-intersecting) quadrilateral
whose four sides all have the same length. Another name is
equilateral quadrilateral, since equilateral means that all of its
sides are equal in length. The rhombus is often called a diamond,
after the diamonds suit in playing cards which resembles the
projection of an octahedral diamond, or a lozenge, though the
former sometimes refers specifically to a rhombus with a 60°
angle (see Polyiamond), and the latter sometimes refers
specifically to a rhombus with a 45° angle.
Input:
Two adjoined sides and the diagonal.
1 <= ai, bi, ci <= 1000, ai + bi > ci
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int rect = 0;
int hisi = 0;
// Initialize variables
rect = 0;
hisi = 0;
scanf("%d", &h1);
scanf("%d", &h2);
scanf("%d", &t);
if (t * t == h1 * h1 + h2 * h2)
rect++;
if (h1 == h2)
hisi++;
if (rect > 0)
printf("\nThis is a rectangle.");
if (hisi > 0)
printf("\nThis is a rhombus.");
return 0;
Copy
Sample Output:
Input two adjoined sides of the parallelogram:
3
4
This is a rhombus.
Sample Output:
Input an integer created by 8 numbers (0 to 9):
25346879
Input:
Data is a sequence of 8 numbers (digits from 0 to 9).
Output:
The difference between the largest integer and the smallest
integer.
Sample Solution:
C Code:
#include<stdio.h>
int main() {
scanf("%d", &d);
for (i = 0; d != 0; i++) {
s[i] = d % 10;
d /= 10;
t = s[j - 1];
s[j - 1] = s[j];
s[j] = t;
}
}
max_val = 0;
max_val *= 10;
max_val += s[i];
t = s[i];
s[7 - i] = t;
min_val = 0;
min_val *= 10;
min_val += s[i];
}
// Calculate and display the difference between the largest and
smallest integers
return 0;
Copy
Sample Output:
Input an integer created by 8 numbers (0 to 9):
25346879
Sample Output:
Input number of straight lines:
2
Maximum number of regions obtained by drawing 2 given straight
lines:
4
Input:
(1 ≤ n ≤ 10,000)
C Code:
#include <stdio.h>
int main() {
long n;
scanf("%ld", &n);
printf("%ld\n", (n*n+n+2)/2);
return 0;
Copy
Sample Output:
Input number of straight lines:
2
Maximum number of regions obtained by drawing 2 given straight
lines:
4
Sample Output:
Input Sentences with positive integers:
5littleJackand2mouse.
Input:
Sentences with positive integers are given over multiple lines.
Each line is a character string containing one-byte alphanumeric
characters, symbols, spaces, or an empty line. However the input
is 80 characters or less per line and the sum is 10,000 or less
Sample Solution:
C Code:
#include <stdio.h>
#include <stdlib.h>
char text[128];
int main(void) {
int i, j, k;
int result = 0;
char temp[8];
// Prompt user to input sentences with positive integers
scanf("%s", text);
i = 0;
while (text[i]) {
for (; (text[i] < '0' || '9' < text[i]) && text[i]; i++);
for (j = 0; '0' <= text[i] && text[i] <= '9'; j++, i++) {
temp[j] = text[i];
temp[j] = '\0';
result += atoi(temp);
return 0;
Copy
Sample Output:
Input Sentences with positive integers:
5littleJackand2mouse.
Sample Output:
English sentences consisting of delimiters and alphanumeric
characters on one line:
w3resource.com
Input:
English sentences consisting of delimiters and alphanumeric
characters are given on one line.
Sample Solution:
C Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main() {
char input_text[1536];
int ctr = 0;
char * temp;
fputs(temp, stdout);
puts("");
return (0);
Copy
Sample Output:
English sentences consisting of delimiters and alphanumeric
characters on one line:
w3resource.com
Sample Output:
Input a positive integer:
25
C Code:
#include <stdio.h>
#include <stdlib.h>
int n, result, x;
int main(void) {
scanf("%d", &n);
result = 0;
printf("%d\n", result);
return 0;
Sample Output:
Input a positive integer:
25
Input:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
n th row of the table
The input ends with a line consisting of a single 0.
Sample Output:
Input number of rows/columns:
4
Input the cell value
Result:
25 69 51 26 171
68 35 29 54 186
54 57 45 63 219
61 68 47 59 235
208 229 172 202 811
Input:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
n th row of the table
The input ends with a line consisting of a single 0.
Output:
For each dataset, print the table with sum of rows and columns.
Sample Solution:
C Code:
#include <stdio.h>
int main() {
int cell_data[11][11];
int i, j, n, sum_val;
scanf("%d", &n);
if (n > 0) {
scanf("%d", &cell_data[i][j]);
printf("\nResult:\n");
sum_val = 0;
sum_val += cell_data[j][i];
cell_data[n][i] = sum_val;
sum_val = 0;
sum_val += cell_data[i][j];
cell_data[i][n] = sum_val;
sum_val = 0;
sum_val += cell_data[n][i];
cell_data[n][n] = sum_val;
printf("%5d", cell_data[i][j]);
printf("\n");
Copy
Sample Output:
Input number of rows/columns:
4
Input the cell value
Result:
25 69 51 26 171
68 35 29 54 186
54 57 45 63 219
61 68 47 59 235
208 229 172 202 811
Sample Output:
Input pairs of a word and a page_no number:
Twinkle
65
Twinkle
55
Little
25
Star
35
^Z
Input:
word page_number
Output:
word
a_list_of_the_page_number
word
a_list_of_the_Page_number
Sample Solution:
C Code:
#include<stdio.h>
#include<string.h>
typedef struct{
int page_no;
char word[50];
} STR;
main(){
int i=0,j,k;
int count=0;
while(scanf("%s %d",str[i].word,&str[i].page_no)!=EOF){
i++;
for(k=i-1;0<k;k--){
if(strcmp(str[k].word,str[k-1].word)<0){
temp=str[k];
str[k]=str[k-1];
str[k-1]=temp;
else if(strcmp(str[k].word,str[k-1].word)==0){
if(str[k].page_no<str[k-1].page_no){
temp=str[k];
str[k]=str[k-1];
str[k-1]=temp;
for(j=0;j<i;j++){
if(j!=0){
if(strcmp(str[j].word,str[j-1].word)==0){
printf(" %d",str[j].page_no);
else{
printf("\n%s\n%d",str[j].word,str[j].page_no);
else{
printf("%s\n%d",str[j].word,str[j].page_no);
printf("\n");
return 0;
Copy
Sample Output:
Input pairs of a word and a page_no number:
Twinkle
65
Twinkle
55
Little
25
Star
35
^Z
Sample Output:
Input an expression using +, -, *, / operators:
1+6*8-4/2
47
Sample Output:
Input an expression using +, -, *, / operators:
25/5-6*7+2
-35
Sample Output:
Input an expression using +, -, *, / operators:
9+6+(5*2)-5
20
Sample Solution:
C Code:
#include <stdio.h>
#include <string.h>
// Function declarations
int addsub();
int muldiv();
int term();
int term(){
int n = 0;
if(input[pos] == '('){
if(input[pos] == ')'){
}else{
int muldiv(){
int first,second;
for(;;){
if(input[pos] == '*'){
}else{
int addsub(){
int first,second;
for(;;){
if(input[pos] == '+'){
}else{
int main(){
int n,i,j;
Copy
Sample Output:
Input an expression using +, -, *, / operators:
1+6*8-4/2
47
Sample Output:
Input an expression using +, -, *, / operators:
25/5-6*7+2
-35
Sample Output:
Input an expression using +, -, *, / operators:
9+6+(5*2)-5
20