Btech First Year Programming Project File
Btech First Year Programming Project File
UNIVERSITY
COMPUTER PROGRAMMING
FUNDAMENTALS
THEORY - # is a preprocessor directive which indicates that the lines beginning with # will be processed by the compiler the
compilation of code. Stdio is a header file which stands for standard input output and facilities in input output. Header files contain
pre-defined functions, etc which can be directly used in the code. Void is return type of the function which indicates that the
function doesn’t return any value. Main is the function name which marks the point of beginning of compilation of program. Printf
is a pre-defined function used for displaying output on the screen. In this problem, we have to display a string on the output screen
for which printf can be used.
PROGRAM -
#include<stdio.h>
#include< conio.h>
int main()
{ printf(“Hello World”);
getch();
}
OUTPUT –
RESULT -
The given string “Hello World!” is displayed on the screen.
CONCLUSION -
This program familiarizes us with the basics structure of C programming and various basic components use in C
programming like header files, standard input output, functions etc. We can use printf() function to display output on the
screen.
PROGRAM 2
THEORY – The if-else statement in C is used to perform the operations based on some specific condition. The
operations specified in if block are executed if and only if the given condition is true. The if statement is used to check
some given condition and perform some operations depending upon the correctness of that condition. It is mostly used in
the scenario where we need to perform the different operations for the different conditions.
PROGRAM –
#include<stdio.h>
int main()
{ int a;
scanf("%d",&a);
if(a%2==0)
else
return 0; }
OUTPUT –
RESULT – The number entered by the user was checked using if-else statement and then output was displayed
accordingly.
CONCLUSION – This program familiarizes us with the use of condition statements in C programming and basic
structure of if-else statement.
PROGRAM 3
THEORY – The switch statement in C is an alternate to if-else-if ladder statement which allows us to execute
multiple operations for the different possible values of a single variable called switch variable. Here, We can define
various statements in the multiple cases for the different values of a single variable. First, the integer expression specified
in the switch statement is evaluated. This value is then matched one by one with the constant values given in the different
cases. If a match is found, then all the statements specified in that case are executed along with the all the cases present
after that case including the default statement. No two cases can have similar values. If the matched case contains a break
statement, then all the cases present after that will be skipped, and the control comes out of the switch. Otherwise, all the
cases following the matched case will be executed.
PROGRAM –
#include<stdio.h>
int main()
int x,y,temp;
scanf("%d",&x);
scanf("%d",&y);
scanf("%d",&temp);
switch(temp)
case 1:
printf("%d",x+y);
break;
case 2:
printf("%d",x-y);
break;
case 3:
printf("%d",x*y);
break;
case 4:
printf("%d",x/y);
break; }
return 0;
OUTPUT –
RESULT –
The numbers entered by the user were undergone operations using switch statement according to the operation choosed
by the user and the desired output was displayed on the screen
CONCLUSION –
This program familiarizes us with the use of condition statements in C programming and basic structure of switch case
statement.
PROGRAM 4
THEORY – Average of two numbers is basically the sum of both the numbers divided by two. In order to find the
average we can use basic algorithm of finding the sum of two numbers then dividing it by two. We will use float data
type for defining the variable of average, as the average may come in decimals also.
PROGRAM –
#include<stdio.h>
int main()
{ int a, b;
float avg;
return 0;
OUTPUT –
CONCLUSION - This program familiarizes us with the use of different datatypes in C programming and basic
structure of defining an equation.
PROGRAM 5
THEORY – Simple interest of principal, rate and time is basically the product of all of them divided by hundred. In
order to find the simple interest we can use basic algorithm of finding the product of numbers and then dividing it by
hundred. We will use float data type for defining the variable of simple interest, as it may come in decimals also.
PROGRAM –
#include<stdio.h>
int main()
int p, r, t;
float si ;
scanf("%d%d%d",&p,&r,&t);
si=(p*r*t)/100.00;
return 0; }
OUTPUT –
CONCLUSION – This program familiarizes us with the use of different datatypes in C programming and basic
structure of defining an equation.
PROGRAM 6
THEORY – When a series of decision is required, nested if-else is used. Nesting means using one if-else construct
within another one. This type of structure is known as the else-if ladder. This chain generally looks like a ladder hence it
is also called as an else-if ladder. The test-expressions are evaluated from top to bottom. Whenever a true test-expression
if found, statement associated with it is executed. When all the n test-expressions becomes false, then the default else
statement is executed.
PROGRAM –
#include<stdio.h>
int main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>=b)
{if(a>=c)
{ printf("%d",a); }
else
printf("%d",c);
else
if(b>=c)
{ printf("%d",b); }
else
printf("%d",c);
return 0; }
OUTPUT –
RESULT – The greatest of the three numbers was displayed on the screen.
CONCLUSION - This program familiarizes us with the use of nested if-else statement in C programming and how
to use nested if-else in conditions where more than two cases are formed.
PROGRAM 7
THEORY – Firstly ten values are entered then they are stored in an array of size 10 let ar[ ] be an array holding these
values. Let us consider a variable 'greatest'. At the beginning of the loop, variable 'greatest' is assigned with the value of
the first element in the array greatest=a[0]. For each value of 'i', value of a[i] is compared with value of variable
'greatest'. If any value greater than the value of 'greatest' is encountered, it would be replaced by a[i]. After completion of
'for' loop, the value of variable 'greatest' holds the greatest number in the array.
PROGRAM –
#include<stdio.h>
int main()
int ar[10],temp;
for(int i=0;i<10;i++)
scanf("%d",&ar[i]);
temp=ar[0];
for(int i=0;i<10;i++)
if(ar[i]>temp)
temp=ar[i];
} }
return 0;
}
OUTPUT –
RESULT –
The greatest of the ten numbers was displayed on the screen.
CONCLUSION –
This program familiarizes us with the use of arrays in C programming and how to use array to take multiple inputs from
the user where many inputs are required.
PROGRAM 8
THEORY – Patterns can be printed in c using nested for and while loops. To print a pattern it is necessary that nested
for loops work with two variables one for manipulation of rows and other for columns. For printing different patterns
different conditions can be used.
PROGRAM –
#include <stdio.h>
int main()
scanf("%d",&rows);
{ printf(" "); }
while(k != 2*i-1)
{ printf("* ");
++k; }
printf("\n"); }
return 0;
OUTPUT –
CONCLUSION – This program familiarizes us with the use of nested for loops in C programming to print different
types of patterns.
PROGRAM 9
THEORY – The Fibonacci sequence is a series where the next term is the sum of pervious two terms. The first two
terms of the Fibonacci sequence is 0 followed by 1.
PROGRAM –
#include<stdio.h>
int main()
printf("ENTER THE NUMBER UPTO WHICH YOU WANT TO PRINT FIBONACCI SERIES-\n");
scanf("%d",&n);
while(n-2>0) {
c=a+b;
printf(",%d",c);
a=b;
b=c;
n-=1; }
return 0; }
OUTPUT –
CONCLUSION – Fibonacci series can be printed by both by using loop and recursion. Here we have used looping
for printing Fibonacci series.
PROGRAM 10
THEORY – This program takes an integer input from the user. Then the while loop is used until n != 0 is false. In
each iteration of while loop, the remainder when n is divided by 10 is calculated and the value of n is reduced by times.
PROGRAM –
#include<stdio.h>
int main()
int n, t;
printf("ENTER A NUMBER-\n");
scanf("%d",&n);
while(n>0)
{ t=n%10;
printf("%d",t);
n=n/10;
return 0; }
OUTPUT –
RESULT – The reverse of the entered number was displayed on the screen.
THEORY- This program takes a positive integer from the user and computes factorial using for loop.
PROGRAM
#include <stdio.h>
int main()
{int i,n=1,a;
scanf("%d",&a);
if(a<0)
printf("error");
else
for(i=1;i<=a;i++)
n=n*i;
printf("factorial is>%d",n);
return(0);
OUTPUT
THEORY- A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year
is a leap year only if it is perfectly divisible by 400.
PROGRAM
#include <stdio.h>
int main()
{int n;
scanf("%d",&n);
if(n%100==0)
if(n%400==0)
printf("year is leap");
else
else if(n%4==0)
printf("year is leap");
else
return(0);}
OUTPUT
THEORY - In this program, two integers entered by the user are stored in variable n1 and n2.Then, for loop is
iterated until i is less than n1 and n2. In each iteration, if both n1 and n2 are exactly divisible by i, the value of i is
assigned to gcd. When the for loop is completed, the greatest common divisor of two numbers is stored in
variable gcd.
PROGRAM
#include <stdio.h>
int main() {
a = x;
b = y;
while (b != 0) {
t = b;
b = a % b;
a = t; }
gcd = a;
lcm = (x*y)/gcd;
return0;}
OUTPUT
RESULT - The lcm and hcf have been found by using simple mathematics.
CONCLUSION - This program familiarizes us with the use of mathematical formulas with loops in a program.
PROGRAM 14
THEORY- A linear search or sequential search is a method for finding an element within a list. It sequentially
checks each element of the list until a match is found or the whole list has been searched.
PROGRAM
#include <stdio.h>
int main()
{int a[100],i,e,n;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&e);
for(i=0;i<n;i++)
{ if(a[i]==e)
break; } }
if(i==n)
return(0); }
OUTPUT
CONCLUSION - This program familiarizes with the memory allotment in continuous form in array.
PROGRAM 15
THEORY – A string is said to be palindrome if it does not gets altered even if we reverse the original string. We
would first take a string and check it whether it is palindrome or not.
PROGRAM –
#include<stdio.h>
#include<string.h>
int main()
{ char a[100];
int n, x;
printf("ENTER A STRING\n");
scanf("%s",&a);
n=strlen(a);
for(int i=0;i<n;i++)
{ if(a[i]==a[n-i-1])
{ x=1; }
else
x=0; }
if(x==1)
else
return 0; }
OUTPUT –
RESULT – When a palindrome string was entered then desired output was displayed on the screen.
CONCLUSION – This program familiarizes us with the concept of strings and palindrome.
PROGRAM 16
THEORY – The main idea to find sum of digits can be divided in three steps. Extract last digit of the given
number. Add the extracted last digit to sum. Remove last digit from given number. As it is processed and not
required any more.
PROGRAM –
#include<stdio.h>
int main()
{ int a, n, sum=0;
scanf("%d",&a);
while(a!=0)
n=a%10;
sum+=n;
a=a/10; }
return 0; }
OUTPUT –
CONCLUSION – This program familiarizes us with the concept of number places and while loop.
PROGRAM 17
THEORY – Read the entered string and store the string into the variable ‘s’ using gets(s) function. For loop
iterates through string ‘s’ with the structure for(i=0;s[i];i++), If the ASCII value of s[i] is in the range of 65 to 90 or
97 to 122 then check s[i] is equal to any one of the vowels(a,e,i,o,u).If s[i] is equal to any vowel then increase the
vowel count.
PROGRAM –
#include <stdio.h>
int main() {
int i = 0;
int vowels = 0;
while(s[i++] != '\0')
{ if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' )
vowels++; }
return 0; }
OUTPUT –
CONCLUSION – This program familiarizes us with the concept of strings and if-else statements used in a
loop.