Define a structure to represent a vector ( a series of integer values) and write a modular program to perform the following tasks:
#include <stdio.h>
struct vector
{
int value[20];
}vec;
void main()
{
int i,n,x;
clrscr();
printf("Enter the starting value:");
scanf("%d",&x);
printf("Enter no. of value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
vec.value[i]=x*i;
printf("%d,",vec.value[i]);
}
getch();
}
OUTPUT
Enter the starting value: 10
Enter no. of value: 10
10,20,30,40,50,60,70,80,90,100
- To create a vector
- To modify the value fo a given element
- To multiply by a scalar value
- To display the vector in the form
#include <stdio.h>
struct vector
{
int value[20];
}vec;
void main()
{
int i,n,x;
clrscr();
printf("Enter the starting value:");
scanf("%d",&x);
printf("Enter no. of value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
vec.value[i]=x*i;
printf("%d,",vec.value[i]);
}
getch();
}
OUTPUT
Enter the starting value: 10
Enter no. of value: 10
10,20,30,40,50,60,70,80,90,100
No comments:
Post a Comment