37
“Heaven’s light is our guide” Rajshahi University of Engineering and Technology Dept: Electronics and Telecommunication Engineering Submitted by: Name: Md.Rahabarul Islam Roll no.- 104011 Subject: Assignment of C programming. Course no.: CSE-142 1

C program lab report

Embed Size (px)

Citation preview

Page 1: C program lab report

“Heaven’s light is our guide”

Rajshahi University of Engineering and Technology

Dept: Electronics and Telecommunication Engineering

Submitted by:Name: Md.Rahabarul Islam Roll no.-104011Subject: Assignment of C programming. Course no.: CSE-142

Submitted to:Firoz Mahmud, Lecturer, Dept. of CSE, RUET.

1

Page 2: C program lab report

1. Write a program that shows the summation of positive integer in between lower limit to upper limit.

#include<stdio.h>#include<conio.h>int main(){long int i,a,b,sum=0;printf("enter the lower and upper number:\n");scanf("%d %d",&a,&b);for(i=a;i<=b;i++){ sum+=i;}printf("%ld",sum);getch(); }

2. Write a program that shows the even summation of positive integer in between lower limit to upper limit.

#include<stdio.h>#include<conio.h>int main(){long int i,a,b,sum=0;scanf("%d %d",&a,&b);for(i=a;i<=b;i++){if(i%2==0)sum+=i;}printf("%ld",sum);getch();}

2

Page 3: C program lab report

3. Write a program that show the odd summation of positive integer in between lower limit to upper limit if summation is greater than 9000.

#include<stdio.h>#include<conio.h>int main(){long int i,a,b,sum=0;printf("enter the lower and upper number:\n");scanf("%d %d",&a,&b);for(i=a;i<=b;i++){if(i%2!=0)sum+=i;}if(sum>9000)printf("%ld",sum);elseprintf("sum is smallar than 9000");getch();}

4. Write a program that show the summation of 12.2!+22.3!+32.4!+………..+n2.(n+1)! .

#include<stdio.h>main(){int i,n,r,j=0,k;printf("Enter your limit:\n");scanf("%d",&n);printf("The output is:\n");for(i=1;i<=n;i++){ r=1;for(k=1;k<=i+1;k++)

r*=k;j+=r*i*i;}printf("%d",j); getch();}

3

Page 4: C program lab report

5. Write a program that shows prime/non-prime number.Sample input: 6 Output : 6 is not a prime number

#include<stdio.h>#include<conio.h>int main(){int n,i,c=0;printf("Enter the number:\n");scanf("%d",&n);for(i=1;i<=n;i++){if(n%i==0)c++;}if(c==2)printf("%d is a prime number",n);elseprintf("it is not prime number");getch();}

6. Write a program to generate the all prime numbers of a given range.

#include<stdio.h>#include<conio.h>int main(){int n,i,j,c,a,b;printf("Enter the upper number:\n");scanf("%d",&b);for(i=1;i<=b;i++){c=0;for(j=1;j<=i;j++){if(i%j==0)c++;}if(c==2)printf("\n%d is a prime number\n",i);printf("\n");}getch();}

4

Page 5: C program lab report

7. Write a program for nPr

#include<stdio.h>main(){int i,n,fact=1,sum=1,p,r,c;printf("enter the value of n and r:\n");scanf("%d %d",&n,&r);for(i=1;i<=n;i++)fact=fact*i;c=n-r;for(i=1;i<=c;i++){sum=sum*i;}p=fact/sum;printf("the value of npr is=%d",p);getch();}

8. Write a program for nCr

#include<stdio.h>main(){int i,n,fact=1,sum=1,p,r,c,m=1,e;printf("enter the value of n and r:\n");scanf("%d %d",&n,&r);for(i=1;i<=n;i++)fact=fact*i;c=n-r;for(i=1;i<=c;i++)sum=sum*i;for(i=1;i<=r;i++)m=m*i;p=m*sum;e=fact/p;printf("the value of ncr is=%d",e);getch();}

5

Page 6: C program lab report

9. Write a program that shows the all factorial of positive integer in between lower limit to upper limit.

#include<stdio.h>#include<conio.h>int fact(int i);int main(){int n,i;printf("enter the number:\n");scanf("%d",&n);for(i=1;i<=n;i++){ printf("i!=%d\n",fact(i));}getch();}int fact(int i){if(i<=1)return(1);elsereturn(i*fact(i-1));getch();}

10.Write a program to generrate Fibonacci Series of a given range. (Fibonacci Series= 0 1 1 2 3 5 8 13 …..)

Sample input: 7Output : 0 1 1 2 3 5 8 13 21

#include<stdio.h>main(){int m=0,r=1,p,n,i;printf("Enter the input:\n");scanf("%d",&n);printf("The output is:\n");printf("0 1 ");for(i=0;i<n;i++){p=m+r;m=r;r=p;printf("%d ",p);}getch();}

6

Page 7: C program lab report

11. Write a program that shows the multiplication of two matrix.

#include<stdio.h>#include<conio.h>

void main (){int i,j,k;int a[3][3],b[3][3],c[3][3],sum;for(i=0;i<3;i++){for(j=0;j<3;j++){scanf("%d",&a[i][j]);}}printf("first matrix:\n");for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d",a[i][j]);}printf("\n");}

for(i=0;i<3;i++){for(j=0;j<3;j++){scanf("%d",&b[i][j]);}}printf("secound matrix:\n");for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d",b[i][j]);}printf("\n");}

printf("multiplication:\n");

for(i=0;i<3;i++){for(j=0;j<3;j++){sum=0;

for(k=0;k<3;k++){sum=sum+a[i][k]*b[k][j];}c[i][j]=sum;printf("%d ",c[i][j]);}printf("\n");}getch();}

7

Page 8: C program lab report

12. Write a program that shows a transpose matrix.#include<stdio.h>#include<conio.h>void main (){int i,j;int a[3][3];for(i=0;i<3;i++){for(j=0;j<3;j++){scanf("%d",&a[i][j]);}}printf("the matrix is:\n");for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d ",a[i][j]);}printf("\n");}printf("transpose matrix:\n");for(i=0;i<3;i++){for(j=0;j<3;j++){printf("%d ",a[j][i]);}printf("\n");}getch();}

13.Write a program that the show the average marks of best 3 out of 4 CT.#include<stdio.h>#include<string.h>main(){float avg,k,ct[3],min;int i,d,sum=0;printf("Enter the CT marks:\n");for(i=0;i<=3;i++){scanf("%f",&ct[i]);sum=sum+ct[i];}min=ct[0];for(i=1;i<=3;i++){if(ct[i]<min)min=ct[i];}avg=(sum-min)/3;d=avg;k=avg-d;if(k>0.1)d++;elsed=d; printf("average ct marks=%d",d);getch();}

8

Page 9: C program lab report

14. Write a program that show the output 1 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 5

#include<stdio.h>main(){int n,i,j;printf("Enter the number:\n");scanf("%d",&n);for(i=1;i<=n;i++){for(j=1;j<=n;j++){printf("%d",j);}printf("\n");}getch();}

15. Write a program that show the output 11 21 2 31 2 3 41 2 3 4 5

#include<stdio.h>main(){int n,i,j;printf("Enter the number:\n");scanf("%d",&n);printf("out put is:\n");for(i=1;i<=n;i++){for(j=1;j<=i;j++){printf("%d",j);}printf("\n");}getch();}

9

Page 10: C program lab report

16. Write a program that show the output 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5

#include<stdio.h>#include<conio.h>

void main (){int i,j,n;printf("Enter the number:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)printf(" ");{for(j=1;j<=i;j++)printf("%d",j);}printf("\n");}getch();}

17. Write a program that show the output 1 2 3 4 56 7 8 9 11 12 1316 17 21

#include<stdio.h>main(){int i,j,c=0,n;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<=n;i++){for(j=1;j<=n;j++){c++;if(j>=n-i+2)continue;printf("%d ",c);}printf("\n");}getch();}

10

Page 11: C program lab report

18. Write a program that show the output 12 34 5 67 8 9 1011 12 13 14 15

#include<stdio.h>main(){int n,i,j,c=0;printf("Enter the number:\n");scanf("%d",&n);printf("the output is:\n");for(i=1;i<=n;i++){for(j=1;j<=i;j++){ c++;printf("%d",c);}printf("\n");}getch();}

19. Write a program that show the output 5 4 5

3 4 5 2 3 4 5 1 2 3 4 5

#include<stdio.h>#include<conio.h>

void main (){int i,j,n;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=n;i>=1;i--){for(j=1;j<=i;j++)printf(" ");{for(j=i;j<=n;j++)printf("%d",j);}printf("\n");}getch();}

11

Page 12: C program lab report

20. Write a program that show the output 5 4 3 2 1 4 3 2 1

3 2 1 2 1 1

#include<stdio.h>#include<conio.h>void main (){int i,j,n;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=n;i>=1;i--){ for(j=1;j<=n-i;j++)printf(" ");for(j=i;j>=1;j--)printf("%d",j);printf("\n");}getch();}

21. Write a program that show the output 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9

#include<stdio.h>#include<conio.h>

void main (){int i,j,n;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<=n;i++){for(j=1;j<=n-i;j++)printf(" ");for(j=1;j<=2*i-1;j++)printf("%d",j);

printf("\n");}getch();}

12

Page 13: C program lab report

22. Write a program to read a string and compare it with predefined string “Rajshahi”.

#include<stdio.h>main(){char a1[20],a2[20];printf("enter your first string:\n");gets(a1);printf("enter your second string:\n");gets(a2);if(strcmp(a1,a2)==0)printf("enter string are equal\n");elseprintf("enter string are not equal\n");getch();}

23. Write a program to read a string and print it in reverse order. Sample input: Hello

Output : olleH

#include<stdio.h>#include<string.h>main(){int i,l;char a[20];printf("Enter the input:\n");gets(a);printf("the out put is:\n");l=strlen(a);for(i=l;i>=0;i--){printf("%c",a[i]);}getch();}

13

Page 14: C program lab report

24. Write a program to compute n raised to the power x.Sample input: n=2 x=3 Output : 2^3=8

#include<stdio.h>main(){int i,n,f=1,r,j;printf("Enter base and power:\n");scanf("%d %d",&n,&r);printf("The out put is:\n");for(i=n;i>0;i--){for(j=1;j<=r;j++)f*=i;if(i<n)break;printf("%d",f);}getch();}

25. Write a program that show perfect number or not.Sample input: 6 Output : 6 is a perfect number

#include<stdio.h>#include<conio.h>

void main (){int i,j,n,sum=0;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<n;i++){if(n%i==0)sum+=i;}if(sum==n)printf("%d is a perfect number",n);getch();}

14

Page 15: C program lab report

26. Write a program that shows armstrong number or not.Sample input: 371Output : 371 is a armstrong number

#include<stdio.h>#include<conio.h>void main (){int a,b,c,d,n;printf("enter the input:\n");scanf("%d",&n);printf("The out put is:\n");a=((n%100)-(n%10))/10;b=(n-(n%100))/100;c=n%10;d=a*a*a+b*b*b+c*c*c;if(d==n)printf("%d is a armstrong number",d);getch();}

27. Write a program for the following input & output combinations.Sample input: 10 Output : 1 4 9

#include<stdio.h>main(){int i,j,n;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<=n;i++){j=i*i;if(j>=10)break;printf("%d ",j);}getch();}

15

Page 16: C program lab report

28. Write a program that convert float number into integer number.Sample input : 7.8Output : 8

#include<stdio.h>main(){float n,k;int p;printf("Enter the input:\n");scanf("%f",&n);printf("The out put is:\n");p=n;k=n-p;if(k>=0.1)p++;elsep=p;printf("%d",p);getch();}

29. Write a program that convert uppercase letter to lowercase letter or vice versa.Sample input : WeaReEte’10Output : wEArEeTE’10

#include<stdio.h>#include<string.h>main(){int i,j,l;char a[50];gets(a);l=strlen(a);for(i=0;i<l;i++){if(a[i]>=65&&a[i]<=90)a[i]=a[i]+32;else if(a[i]>=96&&a[i]<=121)a[i]=a[i]-32;}puts(a);getch();}

16

Page 17: C program lab report

30. Write a program that show how many vowels in a word.Sample input : RUET

Output : 2

#include<stdio.h>#include<string.h>main(){char a[100];int i,c=0,l;printf("Enter the input:\n");gets(a);printf("The number of vowel:\n");l=strlen(a);for(i=0;i<l;i++){if(a[i]=='A'||a[i]=='a'||a[i]=='E'||a[i]=='e'||a[i]=='i'||a[i]=='I'||a[i]=='O'||a[i]=='o'||a[i]=='u'||a[i]=='U')c++;}printf("%d",c);getch();}

31 Write a program that show how many consonants in a word.Sample input : RUET

Output : 2

#include<stdio.h>#include<string.h>main(){char a[100];int i,c=0,l,k;printf("Enter the input:\n");gets(a);printf("the number of constant:\n");l=strlen(a);for(i=0;i<l;i++){if(a[i]=='A'||a[i]=='a'||a[i]=='E'||a[i]=='e'||a[i]=='i'||a[i]=='I'||a[i]=='O'||a[i]=='o'||a[i]=='u'||a[i]=='U')c++;}k=l-c;printf("%d",k);getch();}

17

Page 18: C program lab report

32. Write a program that for below:Sample input : we live in Bangladesh

Output : we liveinbangladesh

#include<stdio.h>#include<string.h>main(){char a[100];int i,l;printf("Enter your string:\n");gets(a);printf("The out put is:\n");l=strlen(a);for(i=0;i<l;i++){if(a[i]==' ')printf("\n");elsea[i]=a[i];printf("%c",a[i]);}getch();} 33. Write a program that shows strong number or not.

Sample input: 145Output : 145 is a strong number

#include<stdio.h>main(){int n,a,b,c,i,fact=1,p=1,q=1,m;printf("Enter the number:\n");scanf("%d",&n);a=n%10;for(i=1;i<=a;i++){fact*=i;}b=((n-(n%10))/10)%10;for(i=1;i<=b;i++){p*=i;}c=(n-(n%100))/100;for(i=1;i<=c;i++){q*=i;}m=fact+p+q;if(m==n)printf("%d is a strong number\n",n);elseprintf("it is not a strong number");getch();}

18

Page 19: C program lab report

34. Write a program that shows palindrome number or not.Sample input: 145Output : 145 is not a palindrome number

#include<stdio.h>main(){int n,a,b,c,d;printf("Enter the input:\n");scanf("%d",&n);printf("The out put is:\n");c=n%10;b=((n%100)-(n%10))/10;a=(n-(n%100))/100;d=c*100+b*10+a*1;if(n==d)printf("%d is a palindrome number",n);elseprintf("it is not a palindrome number");getch();}

35. Write a program that shows your given string is palindrome or not.Sample input: ruetOutput : ruet is not a palindrome string

#include<stdio.h>#include<string.h>main(){int d;char a[20],b[20],c[20];printf("Enter your string:\n");gets(a);printf("The output is:\n");strcpy(b,a);strrev(b);if (strcmp(b,a)==0)printf("It is palindrome string");elseprintf("it is not a palindrome string");getch();}

19

Page 20: C program lab report

36. Write a program that convert decimal number to binary number.#include<stdio.h>#include<conio.h>void main(){int d,a[5];int i;printf("Enter the decimal number:\n");scanf("%d",&d);printf("The binery number is:\n");for(i=0;i<=5;i++){a[i]=d%2;d/=2;if(d==0)break;}for(;i>=0;i--)printf("%d",a[i]);getch();}

37. Write a program that convert binary number to decimal number.

#include<stdio.h>#include<conio.h>int main (){long int bin,base=1,dec=0,r;printf("Enter the binary number:");scanf("%ld",&bin);while(bin>0){ r=bin%10;dec+=(r*base);bin/=10;base*=2;}printf("The decimal number =%ld",dec);getch();}

20

Page 21: C program lab report

38. Write a program that convert decimal number to hexadecimal number.

#include<stdio.h>main(){int n;printf("Enter the dfcimal number:\n");scanf("%d",&n);printf("The out put is:\n");printf("%x",n);getch();}

39. Write a program that convert decimal number to octal number.

#include<stdio.h>main(){int n;scanf("%d",&n);printf("%o",n);getch();}

40. Write a program that find out the area of any triangle.

#include<stdio.h>#include<conio.h>

void main (){int a,b;float c;printf("Enter the base of the triangular:\n");scanf("%d",&a);printf("Enter the hight of the triangular:\n");scanf("%d",&b);c=(a*b)/2;printf("the area of the triangular=%.3f\n",c);getch();}

21

Page 22: C program lab report

41. Write a program that find out the volume and surface area of any cylinder.

#include<stdio.h>#include<conio.h>

void main (){int a,b;float d,c;printf("Enter the radius of the cylender:\n");scanf("%d",&a);printf("Enter the hight of the cylender:\n");scanf("%d",&b);d=3.1416*a*a*b;printf("the volume of the cylender=%.3f\n",d);c=2*3.1416*a*(a+b);printf("the surface area of the cylender=%.3f\n",c);getch();}

42. Write a program that can take any character as a input & show ASCII value of that character.

#include<stdio.h>#include<string.h>main(){char a;scanf("%c",&a);printf("%d",a);getch();}

22

Page 23: C program lab report

43. Write a program that shows all perfect number of a given range.

#include<stdio.h>main(){long int i,j,n,sum;printf("Enter the upper input:\n");scanf("%d",&n);printf("The out put is:\n");for(i=1;i<n;i++){ sum=0;for(j=1;j<i;j++)if(i%j==0)sum=sum+j;if(sum==i)printf("%ld\t ",i);}getch();}

44. Write a program that take 10 data from user and find minimum value. Sample input: 10 18 1 29 5 30 4 12 10 98

Output : 1

#include<stdio.h>#include<conio.h>

void main (){int a[10],i,min;for(i=0;i<10;i++){scanf("%d",&a[i]);}min=a[0];for(i=1;i<10;i++){if(a[i]<min)min=a[i];}printf("the minimum value=%d\n",min);getch();}

23

Page 24: C program lab report

45. Write a program that take 10 data from user and find maximum value. Sample input: 10 18 1 29 5 30 4 12 10 98

Output : 98

#include<stdio.h>#include<conio.h>void main (){int a[10],i,min;for(i=0;i<10;i++){scanf("%d",&a[i]);}min=a[0];for(i=1;i<10;i++){if(a[i]>min)min=a[i];}printf("the maximum value=%d\n",min);getch();}

46.  Write a program to sort the data in ascending orderSample input: 10 18 1 29 5 30 4 12 11 98 Output : 1 4 5 10 11 12 18 29 30 98

#include<stdio.h>main(){int a[10],i,max,j;printf("Enter the input:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("The out put is:\n");for(i=0;i<10;i++){for(j=i+1;j<10;j++){if(a[i]>a[j]){max=a[i];a[i]=a[j];a[j]=max;}}printf("%d ",a[i]);}getch();}

24

Page 25: C program lab report

47. Write a program to sort the data in descending orderSample input: 10 18 1 29 5 30 4 12 11 98 Output : 98 30 29 18 12 11 10 5 4 1

#include<stdio.h>main(){int a[10],i,min,j;printf("Enter the input:\n");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("The out put is:\n");for(i=0;i<10;i++){for(j=i+1;j<10;j++){if(a[i]<a[j]){min=a[i];a[i]=a[j];a[j]=min;}}printf("%d ",a[i]);}getch();}

48. Write a program to add two complex number.Sample input: (2 + 5i) + (3+2i)

Output : 5 + 7i

#include<stdio.h>main(){int pr,pi,qr,qi,sr,si;printf("Enter the imaginery and real part of p:\n");scanf("%d",&pr);scanf("%d",&pi);printf("Enter the imaginery and real part of q:\n");scanf("%d",&qr);scanf("%d",&qi);printf("The summation of complex number:\n");sr=pr+qr;si=pi+qi;printf("%d+%di",sr,si);getch();}

25

Page 26: C program lab report

49. Write output & explain step by step for below code.for(dog = 1;dog < 6;dog++) {

for(cat = 1;cat < 6;cat++) {for(pig = 1;pig < 4;pig++) {printf("Dog = %d Cat = %d Pig = %d\n",dog,cat,pig);if ((dog + cat + pig) > 8 ) goto enough;};};};enough: printf("Those are enough animals for now.\n");

The out put is:Dog=1 cat=1 pig=1Dog=1 cat=1 pig=2Dog=1 cat=1 pig=3Dog=1 cat=2 pig=1Dog=1 cat=2 pig=2Dog=1 cat=2 pig=3Dog=1 cat=3 pig=1Dog=1 cat=3 pig=2Dog=1 cat=3 pig=3Dog=1 cat=4 pig=1Dog=1 cat=4 pig=2Dog=1 cat=4 pig=3Dog=1 cat=5 pig=1Dog=1 cat=5 pig=2Dog=1 cat=5 pig=3Those are enough animals for nowHere second for loop and third for loop is worked under the first for loop.so for the value of dog 1,cat and pig are increased gradually.

50. Find the outputs and explain step by step for the problems 6.58( Book:Schaum’s Outlines).

6.58(a):

Out put is:When i=0 x=0When i=5 x=5When i=10 x=15When i=15 x=30

Finally x=30Here when i=0,5,10,15 Then the condition is full fill and then the value of i is added to x.

26

Page 27: C program lab report

6.58(b):Out put is:When i=0 x=1When i=5 x=2When i=10 x=3When i=15 x=4 Finally i=4Here when i=0,5,10,15.Then the condion is full fill and then the value of x is increased gradually.

6.58(c):The out put is:When i=1 x=1When i=2 x=2When i=4 x=3When i=8 x=4 Finally x=4Here in the for loop the increament update the value of i which is shown above.When i=1,2,4,8 Then the condition is full fill and the value of x is increased gradually.

6.58(d):Out put is:When i=1 x=1When i=2 x=0When i=3 x=3When i=4 x=2When i=5 x=7When i=6 x=6When i=7 x=13When i=8 x=12When i=9 x=21

Finally x=21

Here in the for loop the increament update the value of i which is shown aboveWhen i=1,3,5,7,9 Then the condition is full fill and the value of i is added to x.When i=2,4,6,8Then the condition is not full fill and the value of x is decreased gradually.

27

Page 28: C program lab report

6.58(e): Out put is:When i=1 x=1When i=2 x=0When i=3 x=3When i=4 x=2When i=5 x=7When i=6 x=6When i=7 x=13When i=8 x=12When i=9 x=21

Finally x=21Here continue is given after the printf .so,it can not remove any number of x.

6.58(f):Out put is:When i=1 x=1

Finally x=1Here break is given after the printf.so the loop is closed after one cycle.So the out put is 1.

6.58(g):Out put is :When i=0 there is no out put.When i=1 x=0When i=2 x=1,3When i=3 x=5,8,12When i=4 x=15,19,24,30

Finally x=30Here for every value of i the second loop is valid under the value of i.so the out put is found above .In the second for loop the value of i,j is added to x.

6.58(h): The out put is:

When i=0 there is no out put.When i=1 x=0When i=2 x=1When i=3 x=3When i=4 x=6

Finally x=6Here break is given after the printf. So for every value of first for loop, second for loop is Closed after one cycle.so the valid I and j is added to x.so the out put is found Which is shown above.

28

Page 29: C program lab report

6.58(i):The out put is:

When i=0 there is no out put.When i=1 x=0

Finally x=0Here break is given under the first for loop.so for loop is closed after one cycle .so the out put is Found which is shown above.

6.58(j): The out put is: When i=0 there is no out put.When i=1 x=0When i=2 x=0,2When i=3 x=4,5,9When i=4 x=10,14,14,20

Finally x=20Here for every value of i second for loop is valid under the value of i.if the value of k is divided by 2Then x is increased under the condition of if.if k is divided by 3 ,then x is increased under the condition Of else.

6.58(k):The out put is:When i=0 there is no out put.When i=1 x=1When i=2 x=3,5When i=3 x=7,9,12When i=4 x=14,17,20,23

Finally x=23Here for different value of I,j switch function is used in different case.In this way x is increased gradually.6.58(l):The out put is: When i=0 there is no out put.When i=1 x=1When i=2 x=6,11When i=3 x=16,21,24When i=4 x=29,32,35,38

Finally x=38Here for different value of I,j switch function is used in different case.In this way x is increased gradually.

29

Page 30: C program lab report

30