KEMBAR78
FCP Lab Assignment - 05 | PDF | Computing | Computer Science
0% found this document useful (0 votes)
9 views38 pages

FCP Lab Assignment - 05

Uploaded by

R. S. YENYAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views38 pages

FCP Lab Assignment - 05

Uploaded by

R. S. YENYAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

FCP LAB

ASSIGNMENT - 05

NAME – KISHANT KUMAR BHUSHAN

COURSE – 5 YEARS INTEGRATED M.Sc.

BRANCH – M.Sc. PHYSICS

YEAR – M.Sc. I

SEMESTER – 2nd

DIVISION – G

ADMISSION NO. – I20PH010


PRACTICAL – 01
AIM: Print the output for the following
series.
1.a). 1 + 4 – 9 + 16 – 25 + 36 .... + n^2

Programming:-

#include<stdio.h>

void main()

{int i,n,sum1,sum2,sqr1,sqr2,sum;

printf("The Value of n = ");

scanf("%d",&n);

if(n%2==0)

sum1=1;

for(i=2;i<=n;i=i+2)

{sqr1=i*i;

sum1=sum1+sqr1;
}

sum2=0;

for(i=3;i<=n-1;i=i+2)

{sqr2=-i*i;

sum2=sum2+sqr2;

else

sum1=1;

for(i=2;i<=n-1;i=i+2)

{sqr1=i*i;

sum1=sum1+sqr1;

sum2=0;

for(i=3;i<=n;i=i+2)

{sqr2=-i*i;
sum2=sum2+sqr2;

sum=sum1+sum2;

printf("The Value of this Series = %d",sum);

1.b). 1^2 + 2^2 + 3^2 + 4^2 + ......... +n^2

Programming:-
#include<stdio.h>

void main()

{int i,n,sqr,sum;

printf("The Value of n = ");

scanf("%d",&n);

sum=0;

for(i=1;i<=n;i++)

{sqr=i*i;

sum=sum+sqr;

printf("The Value of this Series = %d",sum);


}
1.c). x – x^3/3! + x^5/5! – x^7/7! + x^9/9! ....
Programming:-

#include<stdio.h>

#include<math.h>

void main()

{int n,j,x,f,k;

float sum;

printf("The Value of n = ");

scanf("%d",&n);

printf("The Value of x = ");

scanf("%d",&x);

sum=x;

for(j=2;j<=n;j++)

{f=1;

for(k=1;k<=2*j-1;j++)
f*=k;

if(j%2==0)

sum-=pow(x,2*j-1)/f;

else

sum+=pow(x,2*j-1)/f;

printf("The SUM = %0.4f",sum);

}
1.d). Given Number is Armstrong number or
Not. (135 = 13 + 33 + 53)
Programming:-

#include<stdio.h>

void main()

{int i,n,r,b,c,num,cube,sum;

printf("The Value of n = ");

scanf("%d",&n);

b=1*n;

c=1*b;

num=0;

while(n>0)

{r=n%10;

num=num+1;

n=n/10;
}

sum=0;

while(b>0)

{r=b%10;

cube=1;

for(i=1;i<=num;i++)

{cube=cube*r;

sum=sum+cube;

b=b/10;

if(c==sum)

printf("This %d is an Armstrong Number.",c);

else

printf("This %d is not an Armstrong Number.",c);


}
1.e). Given Number is Strong number or Not.
(145 = 1! + 4! + 5! )
Programming:-

#include<stdio.h>

void main()

{int n,r,b,i,sum,fact;

printf("The Value of n = ");

scanf("%d",&n);

b=1*n;

sum=0;

while(n>0)

{r=n%10;

fact=1;

for(i=1;i<=r;i++)

{fact=fact*i;
}

sum=sum+fact;

n=n/10;

if(b==sum)

printf("This %d is a Strong Number",b);

else

printf("This %d is not a Strong Number",b);


}
PRACTICAL – 02
AIM: Print the following patterns: (Nested for
loops).
2.A). *
**
***
****
Programming:-

#include<stdio.h>

void main()

{int i,j,k,b=5;

char x;

for(i=1;i<=4;i++)

{printf("\t");

for(j=1;j<=b-i;j++)
{printf(" ");

for(k=1;k<=2*i-1;k++)

if(k%2==1)

x='*';

printf("%c",x);

else

printf(" ");

printf("\n");

}
}
2.B). 12345
1234
123
12
1
Programming:-

#include<stdio.h>

void main()

{int b=6,i,j;

for(i=1;i<=5;i++)

printf("\t");

for(j=1;j<=b-i;j++)

printf("%d",j);

}
printf("\n");

}
2.C). 1
41
941
16 9 4 1
25 16 9 4 1
Programming:-

#include<stdio.h>
void main()
{int i,j;

for(i=1;i<=5;i++)
{
printf("\t");

for(j=i;j>=1;j--)
{
printf("%d ",j*j);

printf("\n");
}

2.D). 1 1
12 21
123 321
1234 4321
12345 54321
Programming:-

#include<stdio.h>

void main()

{int i,j,k,l,b=11;

for(i=1;i<=5;i++)

{printf("\t");

for(j=1;j<=i;j++)

{printf("%d",j);

for(k=1;k<=b-2*i;k++)

{printf(" ");
}

for(l=i;l>=1;l--)

{printf("%d",l);

printf("\n");

2.E). 1
12
123
1234
12345
1234
123
12
1
Programming:-

#include<stdio.h>

void main()

{int i,j,b=5;

for(i=1;i<=5;i++)

{printf("\t");

for(j=1;j<=i;j++)
{printf("%d",j);

printf("\n");

for(i=1;i<=4;i++)

{printf("\t");

for(j=1;j<=b-i;j++)

{printf("%d",j);

printf("\n");

}
2.F). A
ACE
ACEGI
ACEGIKM
ACEGIKMOQ
ACEGIKM
ACEGI
ACE
A
Programming:-

#include<stdio.h>

void main()

{int i,j,b=5;

char x;

for(i=1;i<=5;i++)

{printf("\t");
for(j=1;j<=b-i;j++)

{printf(" ");

for(x='A';x<='A'+4*i-4;x+=2)

{printf("%c",x);

printf("\n");

for(i=1;i<=4;i++)

{printf("\t");

for(j=1;j<=i;j++)

{printf(" ");

for(x='A';x<='A'+16-4*i;x+=2)

{printf("%c",x);

}
printf("\n");

PRACTICAL -03
AIM: Write a program to do the following task
a) Accept any 2 positive numbers, say n1
and n2. Assume n1 > n2.
b) Print all even numbers that lie
between n1 and n2.
c) Print the total number of even
numbers between n1 and n2.
Programming:-

#include<stdio.h>

void main()

{int n1,n2,num,i;

printf("The Value of n1 = ");

scanf("%d",&n1);

printf("The Value of n2 = ");

scanf("%d",&n2);
num=0;

for(i=n2+1;i<=n1-1;i++)

if(i%2==0)

{printf("\n%d\n",i);

num=num+1;

printf("\nThe Total Number of Even No.s = %d",num);

}
PRACTICAL – 04
AIM: Write a program to calculate the sum of
the square of each digit of the given
number.
[E.G. 4534 :- 4^2 + 5^2 + 3^2 + 4^2 = 66]
Programming:-

#include<stdio.h>

void main()

{int n,r,sqr,sum;

printf("The Value of n = ");

scanf("%d",&n);

sum=0;

while(n>0)

{r=n%10;
sqr=r*r;

sum=sum+sqr;

n/=10;

printf("\nThe SUM of Square of each digit of the given Number =


%d",sum);

}
PRACTICAL – 05
AIM: Accept 2 four-digit positive integers then
calculate and display the sum of the
product of each pair of digits occupying
the same position in the two numbers.
[E.G. if the first number is 3445 and the
second number is 4534 then the
output will be 64.]
(Example: 3 * 4 + 4 * 5 + 4 * 3 + 5 * 4 = 64)
Programming:-

#include<stdio.h>

void main()

{int n1,n2,r1,r2,mult,sum;

printf("The Value Of n1 = ");

scanf("%d",&n1);
printf("The Value of n2 = ");

scanf("%d",&n2);

sum=0;

while(n1>0&&n2>0)

{r1=n1%10;

r2=n2%10;

mult=r1*r2;

sum=sum+mult;

n1/=10;

n2/=10;

printf("\nThe SUM = %d",sum);

You might also like