Professional Documents
Culture Documents
Assignment Kanchan
Assignment Kanchan
1 Question 1
1.1 Algorithm
• Take input of n
• get output
• stop
1.2 Flowchart
1
Figure 1: Flowchart of Question 1
2
1.3 C program
#include <s t d i o . h>
int main ( ) {
// d e c l a r e t h e v a r i a b l e names
int i , n , sum a2 , sum b2 , sum ab , r e s u l t ;
p r i n t f ( ” e n t e r t h e v a l u e o f n \n” ) ;
s c a n f ( ”%d” ,&n ) ;
int a [ n ] , b [ n ] , c [ n ] , d [ n ] ;
// i n i t i a l i s e t h e v a r i a b l e
sum a2 =0;
sum b2 =0;
sum ab =0;
r e s u l t =0;
// d e f i n e t h e v e c t o r s a , b , c , d
f o r ( i =1; i<=n ; i ++)
{
a [ i ]= i ;
b [ i ]= i +1;
c [ i ]= i −1;
d [ i ]=a [ i ]+b [ i ] ;
}
// c a l c u l a t e t h e d o t p r o d u c t
f o r ( i =1; i<=n ; i ++)
{
sum a2 += a [ i ] ∗ a [ i ] ;
sum b2 += b [ i ] ∗ b [ i ] ;
sum ab += a [ i ] ∗ b [ i ] ;
}
// c a l c u l a t e t h e o u t p u t
r e s u l t =(sum a2 ∗ sum b2 )−( sum ab ∗ sum ab ) ;
p r i n t f ( ” output=%d\n” , r e s u l t ) ;
}
1.4 Output
For n=10 ; ||a ∗ b||2 = 825.00
For n=50 ; ||a ∗ b||2 = 520625.00
For n=100 ; ||a ∗ b||2 = 8332500.00
For n=500 ; ||a ∗ b||2 = 5208312500.00
3
2 Question 2
2.1 Algorithm
• Take input n
2.2 Flowchart
4
Figure 2: Flowchart of Question 2
5
2.3 C program
#include <s t d i o . h>
#include <math . h>
int main ( ) {
// read t h e v a l u e o f n
p r i n t f ( ” e n t e r t h e v a l u e o f n\n” ) ;
s c a n f ( ”%d” ,&n ) ;
int a [ n ] , b [ n ] , c [ n ] , d [ n ] ;
// d e f i n e t h e a r r a y s a [ n ] , b [ n ] , c [ n ] , d [ n ]
f o r ( i =1; i<=n ; i ++)
{
a [ i ]= i ;
b [ i ]= i +1;
c [ i ]= i −1;
d [ i ]=a [ i ]+b [ i ] ;
// p r i n t f (” r e s u l t=%d\n ” , a [ i ] ) ;
}
6
}
2.4 Output
For n=1000 ; value of (a ∗ b).(c ∗ d)= 249999750000.00
For n=5000 ; value of (a ∗ b).(c ∗ d)=156249993750016.00
3 Question 3
3.1 Algorithm
• Repeat the step 2 until J is reach to 10
• Assign 7600+(50 ∗ j) as the value and print the value
• obtaine the vector C = A+B for p = q = 10. where p ⇒ dimension of A
and q ⇒ dimension of B
3.2 Flowchart
3.3 C program
7
Figure 3: Flowchart of Question 3
8
#include <s t d i o . h>
long double out ( n )
{
printf (”(” );
f o r ( int j = 1 ; j <= n ; ++j )
{
long double v a l u e ;
v a l u e = 7600 + ( 5 0 ∗ j ) ;
p r i n t f ( ”%.2 Lf ” , v a l u e ) ;
printf (” , ” );
}
p r i n t f ( ” ) \ n” ) ;
// p r i n t t h e v a l u e o f ( a . b )
long double sum1 = 0 ;
f o r ( int j = 1 ; j<= n ; j ++)
{
sum1 = sum1 + ((5050+100∗ j )∗(2550 −50∗ j ) ) ;
}
return sum1 ;
}
int main ( )
{
// f o r ( i n t i =10; i <=50; i ++){
p r i n t f ( ” v a l u e f o r 10 i s : ” ) ;
p r i n t f ( ” v a l u e o f A. B : %.2 Lf \n : ” , out ( 1 0 ) ) ;
}
OUTPUT
/tmp/tkFrz6OwJE . o
v a l u e f o r 10 i s : ( 7 6 5 0 . 0 0 , 7 7 0 0 . 0 0 , 7 7 5 0 . 0 0 , 7 8 0 0 . 0 0 , 7 8 5 0 . 0 0 , 7 9 0 0 . 0 0 , 7 9
v a l u e o f A. B : 1 2 6 9 8 7 5 0 0 . 0 0
:
3.4 Output
Value for 10 is : (7650.00 , 7700.00 , 7750.00 ,7800.00 ,7850.00 ,7900.00 , 7950.00
, 8000.00 , 8050.00 , 8100.00 )
value for A.B : 126987500.00