SPA Programs



Here are few more programs which may be useful for SPA conceptual understanding.

1.Write a program to display the multiplication table of a user entered number. The table must be upto 10.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n; clrscr();
printf("Enter a number: "); scanf("%d",&n); for(i=1;i<=10;i++)
{
printf("%d X %d = %d\n",n,i,(n*i));
}
getch();
}
2. Write a program to calculate the value of the following series.

1+1/2+1/3+1/4....1/n
#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++)
{
sum=sum+1.0/i;
}
printf("The value of the series is:%f",sum); getch();
}
3.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();


}
4. Write a program to display the following for the users 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);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}




Hope this is useful to all of youll!

Happy coding!

Enjoy!!

0 comments:

SPA Easy Programs

SPA Programs

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 salarythat 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();
}
3.Write a program to accept the length and breadth of a rectangle from the user.
Calculate and display the area and perimeter. #include<stdio.h>
#include<conio.h> void main ()
{
float length, breadth, area, perimeter; clrscr();
printf("Enter the length and breadth of the rectangle:"); scanf("%f%f",&length,&breadth);
area= length * breadth; perimeter= 2* (length + breadth);
printf("The area of rectangle is= %f and its perimeter is = %f", area, perimeter); getch();
}
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();
}

5.Write a program to accept three numbers from user and display the greatest of
three using the conditional operator. #include<stdio.h> #include<conio.h>
void main ()
{
int n1, n2, n3, greater; clrscr();
printf("Enter three numbers:"); scanf("%d %d %d", &n1,&n2,&n3);
greater=(n1>n2)?((n1>n3)?n1:n3):((n2>n3)?n2:n3); printf("The largest number is :%d",greater);
getch();
}


I hope you all find it useful.
Stay tuned for more programs :)
Enjoy and Happy Coding!!

0 comments: