Escolar Documentos
Profissional Documentos
Cultura Documentos
Prepared By,
P.UmaMaheswari
L/EEE
P.Selvabharathi
L/EEE
0 3
Write a program to calculate the simple interest, given the principle, period and rate of interest (Simple
Interest = PNR /100)
Write a program to convert the temperature from Fahrenheit to Centigrade and vice versa.
( F = 1.8 x (C +32)) ; C = ( F- 32) /1.8 )
Write a program to find the largest of 3 numbers using the minimum possible checks. (Simple if)
Write a program to convert binary to decimal number using while loop.
Write a program to find all possible roots of quadratic equation using switch case.
Write a program to read a particular number and to check whether it is a prime number or not.
The Electricity Production company has to print up the bills for its customers at the following rate:
For the 1st 50 KWH
For the next 100 KWH
For the next 200 KWH
For more than 350 KWH
rate is Rs.2
rate is Rs.6
rate is Rs.7
rate is Rs.8
Write a program to do the above and the output should be in the following order Customer name, Number
of Units and the Total Bill.
Programs Using Functions:
9.
Write a program using function that will round a floating point number to an indicated decimal place. For
example, the number 12.758
10. Would Yield the value 12.76 when it is rounded off to two decimal places.
11. Write a function exchange to interchange the values of two variables say X and Y
12. Write a recursive function that will generate and print first n Fibonacci series.
Programs Using Arrays:
13. Write a program to merge two different sized arrays and eliminate the duplicate from the merged array.
14. Write a menu driven program for inserting an element into an array and for deleting an element from the
array. Program should also have the provision for deleting the duplicates in an array.
15. Write a program to multiply two matrices. Use separate functions to read, process and print the data in
matrix form. Also find the trace and transpose of the given matrix.
16. A list of N numbers is given. Write a program to find:
a. Their average and standard deviation.
b. The number of integers, which are greater than equal to a specified number in the list.
17. Using arrays write a program to arrange the given set of N numbers in ascending order and hence to pick
the greatest and the smallest number. And also find the presence of a specified number
1. SIMPLE INTEREST
OBJECTIVE:
To calculate the simple interest by using the principle amount, no of years and
rate of interest
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
main()
{
float prin_amt,no_yrs,int_rate;
float SI;
printf("\n Enter the principle amt:");
scanf("%f",&prin_amt);
printf("\n Enter the no of years :");
scanf("%f",&no_yrs);
printf("\n Enter the interest rate :");
scanf("%f",&int_rate);
SI=(prin_amt*no_yrs*int_rate)/100;
printf("\n The simple interst is : %f",SI);
getch();
}
Viva Questions:
1)
2)
3)
4)
5)
6)
7)
case 2:
printf("\n\t Enter the Fahrenheit value :");
scanf("%f",&F);
C=(F-32)/1.8;
printf("\n\t The equivalent Centigrade value :%f C",C);
break;
default:
printf("\n\t Invalid Choice");
}
getch();
}
Questions:
The maximum length of a variable in C is ___
What will be the maximum size of a float variable?
A declaration float a,b; occupies ___ of memory
The size of a String variable is
3. LARGEST OF 3 NUMBERS
OBJECTIVE:
To find the largest of 3 numbers using the minimum possible checks .
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("\n LARGEST AMONG 3 NUMBERS ");
111111
10
Questions:
The bitwise AND operator is used for__________
Which operator has the highest priority?
The type cast operator is represented as____________
Explicit type conversion is known as
11
OBJECTIVE:
To find all possible roots of a quadratic equation using switch case
SOURCE CODE:
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float a,b,c,wsr,root1,root2,s1,s2;
int option;
clrscr();
printf("\n\n \t\t\t ROOTS OF A QUADRATIC EQUATION ");
printf("\n\n\nEnter the values of a,b,c:\n");
scanf("%f %f %f",&a,&b,&c);
wsr=pow(b,2)-(4*a*c);
printf("\n WSR =%f",wsr);
if(wsr==0)
option= 1;
if(wsr>0)
option=2;
if(wsr<0)
option=3;
12
switch(option)
{
case 1:
printf("\n ROOTS ARE REAL AND EQUAL");
root1=(-b/(2*a));
root2=root1;
printf("\n ROOT 1 = %f, \n ROOT 2= %f",root1,root2);
break;
case 2:
printf("\n ROOTS ARE REAL AND UNEQUAL");
root1=-b+sqrt(wsr)/(2*a);
root2=-b-sqrt(wsr)/(2*a);
printf("\n ROOT 1 = %f, \n ROOT 2= %f",root1,root2);
break;
case 3:
printf("\n ROOTS ARE IMAGINARY");
s1=-b/2*a;
s2=sqrt(abs(wsr))/(2*a);
printf("\n ROOT 1=%f+ %fi",s1,s2);
printf("\n ROOT 2%f-%fi",s1,s2);
}
}
13
14
OBJECTIVE:
To check whether the given number is a prime number or not.
SOURCE CODE:
#include<stdio.h>
#include<process.h>
#include<conio.h>
void main()
{
int n,prime,i;
clrscr();
printf("\n\t\t\t PRIME NO ");
printf("\n Enter the number : ");
scanf("%d",&n);
for(i=2;i<n;i++)
{
if(n%i!=0)
prime=1;
else
{
printf("\n\n The given number %d is not a prime number",n);
getch();
15
exit(0);
}
}
printf("\n\n The given number %d is a prime number\n",n);
getch();
}
INPUT & OUTPUT :
PRIME NO
Enter the number : 13
The given number 13 is a prime number
Viva Questions :
1) A pointer to a pointer in a form of__________
2) Pointers are of________
3) Maximum number of elements in the array declaration int a[5][8] is __________
4) Array subscripts in C always start at________
5) A Structure is defined as ______________
16
7. ELECTRICITY BILL
OBJECTIVE:
To print the electricity bill with Customer Name , Number of units and
Total amount
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int initial,final,consumed,amt,ch;
char name[20];
clrscr();
printf("\n\t\t ELECTRICITY BILL");
printf("\n\n Enter the Customer Name :");
scanf("%s",&name);
printf("\n Enter the Final unit
:");
scanf("%d",&final);
printf(" Enter the Initial unit :");
scanf("%d",&initial);
consumed=final-initial;
if(consumed<=50)
amt=consumed*2;
else if(consumed>50 & consumed<=150)
amt=consumed*6;
else if (consumed>150 & consumed<=350)
17
amt=consumed*7;
else if (consumed>350)
amt=consumed*8;
: %d",consumed);
: %d",amt);
getch();
}
Viva :
1. Header files in C contain what ?
2. The printf() function retunes which value when an error occurs?
3. The output of printf("%u", -1) is______
4. An Ampersand before the name of a variable denotes________
5. Null character is represented by_________
6. A statement differs from expression by terminating with a_________
18
OBJECTIVE:
To round off a floating point number using function.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float round(float data,int dig);
void main()
{
float data,result;
int i,j,dig;
clrscr();
printf("\n\n\t\tROUNDING OFF FLOATING NUMBER\n");
printf("\n Enter the data
: ");
scanf("%f",&data);
printf("\n How many digits you want after decimal point? : ");
scanf("%d",&dig);
if(dig<=6)
result=round(data,dig);
else
result=data;
printf("\n The rounded off value of the data %f is: %g",data,result);
getch();
19
}
float round(float data,int dig)
{
long temp,test;
float result;
result=(pow(10,dig+1) * data);
temp=result;
test=temp%10;
if(test>=5)
temp=(temp/10)+1;
else
temp=temp/10;
result=temp/pow(10,dig);
return(result);
}
: 12.456987
20
21
22
23
return 1;
else
return(fibo(i-1)+fibo(i-2));
}
}
FIBONACCI SERIES
Enter the number n: 15
0
21
34
55
89
144
233
377
13
Viva:
1.
24
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],b[50],c[100],n1,n2,i,j,m=0,n=0,dup=0;
clrscr();
printf("\n\t\t MERGING OF ARRAYS WITHOUT DUPLICATE\n");
printf("\nEnter the first array max value: ");
scanf("\t%d",&n1);
printf("\nEnter the first array element: \n");
for(i=0;i<n1;i++)
{
scanf(" %d",&a[i]);
c[m]=a[i];
m++;
}
printf("\nEnter the second array max value: ");
scanf(" %d",&n2);
printf("\nEnter the second array element: \n");
for(i=0;i<n2;i++)
{
scanf(" %d",&b[i]);
c[m]=b[i];
m++;
25
}
for(i=0;i<m;i++)
{
for(j=i+1;j<m;j++)
{
if(c[i]==c[j])
{
dup=1;
break;
}
}
if(dup==0)
{
c[n]=c[i];
n++;
}
dup=0;
}
printf("\nResultant array without duplicate : ");
for(i=0;i<n;i++)
printf("\n %d",c[i]);
getch();
}
26
27
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[10][10],b[10][10],c[10][10],d[10][10],r1,c1,r2,c2,i,j,k;
clrscr();
printf("\n\t\t MATRIX MULTIPLICATION & TRANSPOSE\n");
printf("\nEnter the row & column size of first matrix: ");
scanf("%d %d",&r1,&c1);
printf("\nEnter the row & column size of second matrix: ");
scanf("%d %d",&r2,&c2);
if(c1!=r2)
{
printf("\n \"Matrix multiplication is not possible.Because
R1!=C2\"");
getch();
exit(0);
}
28
else
{
printf("\nEnter the first matrix: \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf(" %d",&a[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
29
30
12
10
40
20
18
40
12
20
10
18
Viva
1) Explain one method to process an entire string as one unit?
2) Difference between calloc() and malloc()?
3) What does it mean when a pointer is used in an if statement?
4) How can you avoid including a header more than once?
31
SOURCE CODE:
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float n,i,sum=0,sqrsum=0,mean,stddev,check;
float data[20],deviation[20],deviasqr[20];
clrscr();
printf("\n \t\t STANDARD DEVIATION \n");
printf("\n Enter the number of elements in data array : ");
scanf("%g",&n);
printf("\n Enter the elements of data array one by one : \n");
for(i=1;i<=n;i++)
scanf(" %g",&data[i]);
for(i=1;i<=n;i++)
sum=sum+data[i];
mean=sum/n;
for(i=1;i<=n;i++)
{
deviation[i]=data[i]-mean;
32
deviasqr[i]=pow(deviation[i],2);
sqrsum=sqrsum+deviasqr[i];
}
stddev=sqrt(sqrsum/n);
printf("\n D\t M\t (D-M)\t
(D-M)(D-M)");
printf("\n _____________________________________");
for(i=1;i<=n;i++)
printf("\n %g\t %g\t %6.2f\t %8.4f", data[i],mean,deviation[i],deviasqr[i]);
printf("\n Sum of deviation square :%g",sqrsum);
printf("\n\n\t\t a). MEAN or AVG = %g \t STDDEVIATION = %g" ,mean,stddev);
printf("\n\n Enter the number to check: ");
scanf("%g",&check);
printf(" \t\t b).The following numbers are greater than the given number :");
for(i=1;i<=n;i++)
{
if(data[i]>check)
printf("\n\t\t
data[%g]=%g",i,data[i]);
}
getch();
}
33
(D-M)
(D-M)(D-M)
_____________________________
1
16.8
-15.80
249.6400
23
16.8
6.20
38.4400
12
16.8
-4.80
23.0400
45
16.8
28.20
795.2401
16.8
-13.80
190.4400
STDDEVIATION = 16.1047
34
Viva
1. When would you use a pointer to a function
2. What is static identifier? 2)Where are the auto variables stored?
3. When does the compiler not implicitly generate the address of the first element of an array?
4. What are the advantages of auto variables?
35
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,temp,a[100],x,found=0;
clrscr();
printf("\n\n\t ARRAY ASCENDING, FINDING GREATEST, SMALLEST AND SPECIFIED
NUMBER");
printf("\n\nEnter the no of datas in array (n) : ");
scanf("%d",&n);
printf("\nEnter the
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
36
}
printf("\nThe sorted array is :");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
printf("\n\nThe minimum value of the array is :
%d",a[0]);
%d",a[n-1]);
37
38
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int vow=0,num=0,cons=0,ws=0,oth=0,i,l;
char n[500];
clrscr();
printf(" \n\n\t\t\tCOUNTING THE NUMBER OF\n\t VOWELS, NUMBERS,
CONSONANTS, WORDS, WHITE SPACES & OTHER CHARACTERS");
printf("\n\n Enter a line of text:\n");
gets(n);
l=strlen(n);
for(i=0;i<=l;i++)
{
if(n[i]=='A'||n[i]=='E'||n[i]=='I'||n[i]=='O'||n[i]=='U'||
n[i]=='a'||n[i]=='e'||n[i]=='i'||n[i]=='o'||n[i]=='u')
vow++;
else if(n[i]>=65 && n[i]<=90 || n[i]>=97 && n[i]<=122)
cons++;
else if(n[i]>=48 && n[i]<=57)
num++;
39
else if(n[i]==32)
ws++;
else if(n[i]>=33 && n[i]<=127)
oth++;
}
printf("\n No of vowels inthe given text
: %d",vow);
: %d",num);
: %d",cons);
: %d",ws);
: %d",ws+1);
:6
:2
:5
:3
:4
40
3. Difference between : - 1)Global variable and Local variable , 2)Static variable and Global
variable ?
4. To which numbering system can the binary number 1101100100111100 be easily converted to?
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[25];
int len,i,j,notpal=0;
clrscr();
printf("\n\n\t\t STRING PALINDROME ");
printf("\n\nEnter the String: ");
scanf("%s",str);
len=strlen(str);
for(i=0,j=len-1;i<=len/2;i++,j--)
{
if(str[i]!=str[j])
{
notpal=1;
break;
}
41
if(notpal==1)
printf("\n\"The given string is not palindrome\"");
else
printf("\n\"The given string is palindrome\"");
getch();
}
STRING PALINDROME
Enter the String: nalam
"The given string is not palindrome"
Viva:
1. How can we read/write structures from/to data files?
2. What is the quickest searching method to use?
3. Differentiate between a linker and linkage?
42
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[20][20],temp[50];
int i,j,n;
clrscr();
printf("\n\t\t SORTING OF NAMES IN ALPHABETICAL ORDER\n");
printf("\nEnter the number of names : ");
scanf("%d",&n);
printf("\nEnter the names one by one :\n");
for(i=0;i<n;i++)
scanf("%s",&name[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if((strcmp(name[i],name[j])>0))
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
43
}
}
printf("\n\t\t SORTED NAMES \n");
for(i=0;i<n;i++)
printf("\n%s",name[i]);
getch();
}
44
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char upper[20],lower[20];
int len,i;
clrscr();
printf("\n\n\t CONVERSION FROM UPPER CASE TO LOWER CASE ");
printf("\n\nEnter the string in uppercase: ");
scanf("%s",upper);
len=strlen(upper);
for(i=0;i<len;i++)
lower[i]=upper[i]+32;
lower[i]='\0';
printf("\n\nThe lower case of \"%s\" is : \"%s\"",upper,lower);
getch();
}
45
Viva:
1. Difference between :- 1) NULL pointer and NULL macro?
2. What is the difference between text and binary modes?
3. C Program to print the following series: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
4. How I can add two numbers in c language without using Arithmetic operators?
46
21.STUDENT DETAILS
OBJECTIVE:
To calculate the average of three marks of students and to store the Rollno, Name,
Mark1, Mark2, Mark3, Total, Average, Result and Class using structure.
SOURCE CODE:
#include<stdio.h>
#include<string.h>
#include<conio.h>
struct stud
{
int rollno,m1,m2,m3,total;
char name[30],grade[30];
float avg;
}s[50];
void main()
{
int i,n;
clrscr();
printf("\n\t\t\t STUDENTS DETAILS ");
printf("\n Enter the number of student:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the student %d details: ",i+1);
printf("\n Roll no :");
scanf("%d",&s[i].rollno);
printf("\n Name
:");
47
scanf("%s",&s[i].name);
printf("\n Mark1
:");
scanf("%d",&s[i].m1);
printf("\n Mark2
:");
scanf("%d",&s[i].m2);
printf("\n Mark3
:");
scanf("%d",&s[i].m3);
if(s[i].m1<50||s[i].m2<50||s[i].m3<50)
strcpy(s[i].grade,"fail");
else
{
s[i].total=s[i].m1+s[i].m2+s[i].m3;
s[i].avg=s[i].total/3;
if(s[i].avg>=75)
strcpy(s[i].grade,"Distinction");
else if(s[i].avg>=60 && s[i].avg<=74)
strcpy(s[i].grade,"First");
else if(s[i].avg>=50 && s[i].avg<=59)
strcpy(s[i].grade,"Second");
}
}
printf("\n\t\t\t STUDENT MARK LIST \n");
printf("\nROLLNO\tNAME\t\tMARK1\tMARK2\tMARK3\tTOTAL\tAVERAGE(%)\t
GRADE");
for(i=0;i<n;i++)
printf("\n%d\t%s\t\t%d\t%d\t%d\t%d\t%g\t\t%s",s[i].rollno,
s[i].name,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].avg,
s[i].grade);
getch();
48
:Bindhu.N
Mark1 :56
Mark2 :65
Mark3 :72
Enter the student 2 details:
Roll no :15
Name
:Shanthi.K
Mark1 :12
Mark2 :45
Mark3 :78
STUDENT MARK LIST
ROLLNO
NAME
02
Bindhu.N
56
65
72
193
64.00
First
15
Shanthi.K
12
45
78
135
45.00
Fail
Viva:
1.
2.
3.
4.
How can I sort things that are too large to bring into memory?
What is the code for clrscr() function?
How do you print only part of a string?
What is the difference between goto and longjmp() and setjmp()?
49
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
struct emp
{
int eno;
char ename[50];
long int basic;
};
void main()
{
double da,hra,cca,pf,gross,net;
struct emp *e,a;
e=&a;
clrscr();
printf("\n\n\t\t EMPLOYEE SALARY DETAILS ");
printf("\n Enter emp no
: ");
scanf("%d",&e->eno);
printf("\n Enter name of the employee : ");
scanf("%s",&e->ename);
printf("\n Enter the basic pay
: ");
scanf("%ld",&e->basic);
da=e->basic*32/100;
hra=e->basic*15/100;
50
cca=e->basic*10/100;
pf=e->basic*15/100;
gross=e->basic+da+hra+cca;
net=gross-pf;
printf("\n\t\t\t PAY SLIP \n");
printf("\nEmployee No : %d",e->eno);
printf("\nName
: %s",e->ename);
: %lf",hra);
printf("\nDA
: %lf",da);
printf("\nPF
: %lf",pf);
: %lf",net);
getch();
: 12
: 15000
PAY SLIP
Employee No
: 12
Name
: Sasikala.B
Basic salary
: 15000
HRA
: 2250.000000
DA
: 4800.000000
PF
: 2250.000000
Gross Salary
: 23550.000000
Net Salary
: 21300.000000
51
Viva :
1. What is the purpose of realloc( )?
2. How do you print only part of a string?
3. What is the difference between goto and longjmp() and setjmp()?
4. How I can add two numbers in c language without using Arithmetic operators?
5. How much memory does a static variable takes?
52
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int vow=0,num=0,cons=0,ws=0,oth=0,i,l;
char *strg;
clrscr();
printf(" \n\n\t\t\tCOUNTING THE NUMBER OF\n\t VOWELS, NUMBERS,
CONSONANTS, WORDS, WHITE SPACES & OTHER CHARACTERS");
printf("\n\n Enter a line of text:\n");
gets(strg);
while(*strg!=\0)
{
if(*strg=='A'||*strg=='E'||*strg=='I'||*strg=='O'||*strg=='U'||
*strg=='a'||*strg=='e'||*strg=='i'||*strg=='o'||*strg=='u')
vow++;
else if(*strg>=65 && *strg<=90 || *strg>=97 && *strg<=122)
cons++;
else if(*strg>=48 && *strg<=57)
num++;
else if(*strg==32)
53
ws++;
else if(*strg>=33 && *strg<=127)
oth++;
strg++;
}
printf("\n No of vowels inthe given text
: %d",vow);
: %d",num);
: %d",cons);
: %d",ws);
: %d",ws+1);
:6
:2
:5
:3
:4
54
55
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
main()
{
char o_arr[12],*d_arr;
int len=0;
clrscr();
printf("\n\n\tSTRING LENGTH & COPYING FUNCTIONS USING POINTER");
printf("\n\n Enter the original array:");
gets(o_arr);
d_arr=o_arr;
printf("\n\n original array :%s",o_arr);
printf("\n\n duplicate array:%s",d_arr);
while(*d_arr!='\0')
{
len++;
d_arr++;
}
printf("\n\n length of the string : %d",len);
getch();
}
56
Viva:
1. what is the difference between the functions memmove() and memcpy()?
2. Write a code for implementation of doubly linked list with use of single pointer in each node
3. When should the register modifier be used? Does it really help?
4. How do you use a pointer to a function?
5. What is a null pointer?
57