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)
{
}
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: