Solution of C Programs For FE SEM II (SPA)
Solution of C Programs For FE SEM II (SPA)
Solution of C Programs For FE SEM II (SPA)
1.
Write a program to calculate the simple interest taking principal, rate of interest and number of years as inputs from user. #include<stdio.h> #include<conio.h> void main () { float rateOfInterest, years, principal, simpleInterest; clrscr(); printf("Enter the principal amount, rate of interest and no. of years:"); scanf("%f%f%f", &principal, &rateOfInterest, &years); simpleInterest = principal * rateOfInterest*years / 100; printf("The simple interest is %f", simpleInterest) ; getch(); }
2.
Write a program to accept basic salary from the keyboard. Calculate the gross salary that includes basic salary, 50% DA and 40% HRA. #include<stdio.h> #include<conio.h> void main () { float basic,hra,da,gross; clrscr(); printf("Enter the basic salary:"); scanf("%f", &basic); hra=40*basic/100; da = 50*basic/100; gross=basic+da+hra; printf("The total salary is %f",gross); getch(); }
Page
4.
Write the program to accept one it type data and one float type data. Multiply the two numbers and display the result. #include<stdio.h> #include<conio.h> void main () { int n1; float n2, result; clrscr(); printf("Enter one integer and one float type number each:"); scanf("%d %f",&n1,&n2); result=n1*n2; printf("The product is :%f",result); getch(); }
Page
6.
Write a program to accept three numbers and find their average. #include<stdio.h> #include<conio.h> void main () { int a, b, c, sum; float avg; clrscr(); printf("Enter three numbers:"); scanf("%d %d %d",&a,&b,&c); sum= a+b+c; avg=sum/3.0; printf("The average is equal to:%f",avg); getch(); }
7.
Page
Page
Page
#include<stdio.h> #include<conio.h> void main() { int i,n; float sum=0.0; clrscr(); printf("Enter a number: "); scanf("%d",&n); for(i=1;i<=n;i++) {
Page
14. Write a program to calculate the sine of an angle using the following series for x as the angle in radians.
#include<stdio.h> #include<math.h> #include<conio.h> void main() { int i, fact=1,sign=-1; float x,numerator,sum,term; clrscr(); printf("Enter an angle in degrees: "); scanf("%f",&x); x=x*3.14/180; term=x; sum=term; for(i=3;term>=0.0000001;i=i+2) { fact=fact*i*(i-1); numerator=pow(x,i); term=numerator/fact; sum=sum + sign * term; sign=sign*-1; } printf("The value of the series is:%f",sum); getch();
Page
16. Write a program to display the following for the user specified number of lines. * ** *** **** ***** ****** ******* ******** | n lines #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf("Enter the number of lines:"); scanf("%d",&n);
Page
Page
18. Write a program to display the following asking the user for the number of lines. A ABA ABCBA ABCDCBA ABCDEDCBA ABCDEFEDCBA #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf("Enter the number of lines:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { printf(" "); } for(j=1;j<=i;j++) { printf("%c",(char)(j+64)); } for(j=i-1;j>=1;j--) { printf("%c",(char)(j+64)); } printf("\n"); } getch(); } 19. Write a program to calculate the value of n-1)!. #include<stdio.h> #include<conio.h>
Page
10
20. Write a program to display first 10 numbers divisible by 5 and 8. #include<stdio.h> #include<conio.h> void main() { int i=0,n=1; clrscr(); while(i<10) { if(n%5==0 && n%8==0) { printf("%d\n",n); i++; } n++;
Page
11
Page
12
Page
13
Page
14
Page
15
Page
16
Page
17
Page
18
30. Write a program to find GCD and LCM of two numbers. #include<stdio.h> #include<conio.h> void main() { int n1,n2,lcm,gcd; clrscr(); printf("Enter two numbers:"); scanf("%d %d",&n1,&n2); if (n1>n2) { lcm=n1; gcd=n2; } else { lcm=n2; gcd=n1; }
Page
19
Page
20
Page
21
Page
22
Page
23
Page
24
Page
25
Page
26
Page
27
Page
28
Page
29
Page
30
Page
31
Page
32
Page
33
Page
34
Page
35
Page
36
Page
37
number:%d\nFees:%f\n",s1.name,s1.roll_no,s1.fees); getch(); } 54. Define structure within structure consisting of following elements: i. ii. iii. iv. Employee Code Employee Name Employee Salary and Employee Date_of_joining
Write a C program to read at least 10 records and display them. #include<conio.h> #include<stdio.h> struct employee { char name[20]; int salary,code; struct { int date,month,year; }date_joining; }; void main () { struct employee e[100]; int i; clrscr(); for(i=0;i<=9;i++) { printf("Enter the employee's name, code, salary and date of joining as date, month and year separately:");
Page
38
%d",e[i].name,&e[i].code,&e[i].salary,&e[i].date_joining.date,&e[i].date_joining.m
printf("%s\t%d\t%d\t%d/%d/%d\n",e[i].name,e[i].code,e[i].salary,e[i].date_join ing.date,e[i].date_joining.month,e[i].date_joining.year); } getch(); } 55. Write a program to accept a set of 10 numbers and print the numbers using pointers. #include<stdio.h> #include<conio.h> void main () { int *p,i,a[10]; clrscr(); p=&a; printf("Enter 10 nos.\n"); for(i=0;i<=9;i++) scanf("%d",(p+i)); for(i=0;i<=9;i++) printf("%d\n",*(p+i)); getch(); } 56. Write a program to accept a set of 10 numbers and print the numbers using pointers. Find average of these integers. #include<stdio.h> #include<conio.h> void main ()
Page
39
Page
40
Page
41
Page
42
Page
43