Document
Document
#include <stdio.h>
#define PI 3.14159
int main() {
double r, a, c;
scanf("%lf", &r);
if (r > 0) {
a = PI * r * r;
c = 2 * PI * r;
} else {
printf("Invalid radius\n");
return 0;
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n % 2 == 0) {
} else {
printf("%d is odd\n", n);
return 0;
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n > 0) {
} else if (n < 0) {
} else {
return 0;
4. Write a program that inputs cost price (CP) and selling price (SP) and
determines whether there is loss or gain.
#include <stdio.h>
int main() {
scanf("%f", &SP);
result = SP - CP;
if (result > 0) {
} else {
return 0;
5. Write a C program that reads three numbers and displays the largest
and the smallest among them.
#include <stdio.h>
int main() {
if (a > b) {
if (a > c) {
largest = a;
} else {
largest = c;
}
} else {
if (b > c) {
largest = b;
} else {
largest = c;
if (a < b) {
if (a < c) {
smallest = a;
} else {
smallest = c;
} else {
if (b < c) {
smallest = b;
} else {
smallest = c;
return 0;
}
6. Write a C program that takes three different numbers and find out the
middle number.
#include <stdio.h>
int main() {
int a, b, c;
if (a > b) {
if (a < c) {
} else if (b > c) {
} else {
} else {
if (a > c) {
} else if (b < c) {
} else {
return 0;
}
7.Write a program to calculate and display real roots of a quadratic
equation. (Hint check condition (b2-4ac)>0 for real root).
#include <stdio.h>
#include <math.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
} else if (discriminant == 0) {
root1 = -b / (2 * a);
} else {
return 0;
0-1000 5%
1001-2000 10%
>2000 12%
#include <stdio.h>
int main() {
scanf("%f", &sales);
} else {
return 1;
return 0;
9. Write Interactive program that takes length and breadth and performs
the following task.
a) Area of rectangle
b) Perimeter of rectangle
c) Exit
#include <stdio.h>
int main() {
int choice;
while (1) {
printf("\nMenu:\n");
printf("3. Exit\n");
scanf("%d", &choice);
if (choice == 1 || choice == 2) {
if (choice == 1) {
} else if (choice == 2) {
break;
} else {
return 0;
10. Write a C program that takes a number less than 10 and display its
multiplication table.
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
} else {
}
return 0;
#include <stdio.h>
int main() {
int term = 1, i;
term += 2;
return 0;
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
return 0;
#include <stdio.h>
int main() {
int n, i, factorial = 1;
scanf("%d", &n);
factorial = factorial*i;
return 0;
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
return 0;
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if(i == 1) {
continue;
if(i == 2) {
continue;
first = second;
second = next;
return 0;
#include <stdio.h>
int main() {
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
n /= 10;
}
if (original == reverse)
else
return 0;
Sum = 1+1/2+1/3+1/4+.........+1/n
#include <stdio.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
sum += 1 / i;
printf("%d", sum);
return 0;
12345
2 4 6 8 10
3 6 9 12 15
#include <stdio.h>
int main() {
for(int i = 1; i <= 3; i++) {
printf("\n");
return 0;
#include <stdio.h>
int main() {
int n, i, count = 0;
scanf("%d", &n);
if (n % i == 0) {
count++;
if (count == 2)
else
return 0;
int main() {
int n, num = 2, c, i, p;
scanf("%d", &n);
p = 1;
if(num % i == 0) {
p = 0;
break;
c++;
return 0;
1. Write a program to input marks of 5 subjects and display the total and
average marks.
#include <stdio.h>
int main() {
float average;
for(int i = 0; i < 5; i++) {
scanf("%d", &marks[i]);
total += marks[i];
return 0;
#include <stdio.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
if(arr[i] % 2 == 0) {
sum += arr[i];
return 0;
3. Write a program to find the position of the key number from given set of
numbers which any stored in an array. [Sequential Search]
#include <stdio.h>
int main() {
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
scanf("%d", &key);
if(arr[i] == key) {
break;
}
}
if(position != -1)
else
return 0;
4. Write a program to read the age of 100 persons and count the number
of persons in the age group between 50 and 60 years.
#include <stdio.h>
int main() {
scanf("%d", &ages[i]);
count++;
printf("%d\n", count);
return 0;
}
87, 34, 91, 29, 72, 94, 62, 39, 46, 66, 98, 96, 10, 48, 57, 97, 65, 67, 59,
17, 57, 23, 10, 86, 37, 47, 65, 83, 27, 17, 4, 61, 71, 25, 47, 27, 48, 67, 85,
43, 43, 51, 65, 63, 62, 49, 34, 16, 14, 66, 28, 68, 27, 87, 18, 65, 18, 23,
94, 7, 81, 32, 57, 80, 77, 2, 20, 48, 6, 34, 43, 84, 63, 52, 84, 10, 61, 81,
51, 7, 14, 99, 23, 44, 70, 86, 95, 16, 4, 32, 81, 19, 3, 29, 50, 50, 63, 46,
68, 1
5. Write a program to input 'n' numbers and find out the greatest and
smallest numbers.
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
int numbers[n];
scanf("%d", &numbers[i]);
greatest = numbers[0];
smallest = numbers[0];
greatest = numbers[i];
smallest = numbers[i];
}
return 0;
6. Write a program that takes salary of 100 employees and print the salary
of the employes ascending order.
#include <stdio.h>
int main() {
scanf("%d", &salaries[i]);
temp = salaries[i];
salaries[i] = salaries[j];
salaries[j] = temp;
}
for (i = 0; i < 100; i++) {
printf("%d\n", salaries[i]);
return 0;
#include <stdio.h>
int main() {
scanf("%d", &matrix[i][j]);
transpose[j][i] = matrix[i][j];
printf("\n");
return 0;
#include <stdio.h>
int main() {
scanf("%d", &matrix[i][j]);
sum += matrix[i][j];
return 0;
}
9. Write a program to calculate the sum of diagonal matrix with size 3X3.
#include <stdio.h>
int main() {
scanf("%d", &matrix[i][j]);
sum += matrix[i][i];
printf("%d\n", sum);
return 0;
10. Write a program to add two matrices with size 2X2 supplying by
elements by the user.
#include <stdio.h>
int main() {
scanf("%d", &matrix1[i][j]);
scanf("%d", &matrix2[i][j]);
printf("\n");
return 0;
8. Write a program to input line of text and count the number of digit,
vowels, consonants, wh spaces and other characters.
10. Write a program to input the names of 10 students and sort them in
alphabetical order.
11. Write a program to search a string from the given set of strings.
Computer Science-1
The character set defines a group of letters, words, numbers, symbols and
expression which is used in C language. The character set in C language
can be grouped into the following three categories.
Letters: upper case A to Z and lowercase a to z
Digits: 0 to 9
Use of Comments
The comments have no effects on program codes but they are useful
components of program for program documentation. They help
programmer for the description of the program codes. They also make
programmer to modify and testing of a progam Comments can be written
in two forms:
/Multi-Line.........................comments/
Keywords
auto
break
double
int
struct
else
long
switch
case
enum
register
typedef
chat
extern
return
union
const
float
short
unsigned
contime
for
If
signed
vuid
diefault
goto
sizeof
volatile
do
static
while
Variable
They must always begin with a letter, although some systems permit
underscore as the first character.
125
(area)
6th
Sun number
Salary
abc
Emp name
averagel
uneric variable: The variable that stores numeric data only is called
numeric variabl The numeric data may be whole number or fractional
number. Examples of numri variables are integer, floating point and
double,
String variable: The variable that stores character data only is called
string variable. The string data may be single character or string.
Examples of string variable are character, array of character (string), table
of strings.
Constant
A constant value is the one which does not change during the execution of
a program C supports several types of constants. These constants are
given below:
Character Constant
Integer Constant