0% found this document useful (0 votes)
7 views17 pages

Document 5

Uploaded by

stevenmathew1212
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)
7 views17 pages

Document 5

Uploaded by

stevenmathew1212
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/ 17

ASSESSMENT NUMBER 3

1.PRINT 1 TO 100

INPUT;#include<stdio.h>

int main()

{for(int i=1;i<=100;i+=1)

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

return 0;}

OUTPUT;dent@OptiPlex-3000-16:~$ ./a.out

10

11

12

13

14

15

16

17

18

19

20
21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51
52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82
83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100.

2.PRINT EVEN NUMBERS UP TO 100.

INPUT;#include<stdio.h>

int main()

{for(int i=2;i<=100;i+=2)

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

return 0;}

OUTPUT;2

8
10

12

14

16

18

20

22

24

26

28

30

32

34

36

38

40

42

44

46

48

50

52

54

56

58

60

62

64

66

68

70
72

74

76

78

80

82

84

86

88

90

92

94

96

98

100.

3.PRINT THE MULTIPLICATION TABLE OF A NUMBER.

INPUT;#include<stdio.h>

int main (){

int num=6;

int i;

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

{printf("%d*%d=%d\n",i,num,i*num);}

return 0;}

OUTPUT;0*6=0

1*6=6

2*6=12
3*6=18

4*6=24

5*6=30

6*6=36

7*6=42

8*6=48

9*6=54

10*6=60

4.FIND THE FACTORS OF A NUMBER.

INPUT;#include<stdio.h>

int main (){

int num=6;

int i;

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

if(num%i==0)

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

OUTPUT;1

5)FIND THE FACTORIAL OF A NUMBER.

INPUT;#include<stdio.h>

int main (){

int n;
printf("enter the number for factorial\n");

scanf("%d",&n);

printf("factorial of %d is",n);

int a=1;

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

{a=a*i;}

printf("%d",a);

return 0;}

OUTPUT;enter the number for factorial

factorial of 6 is720.

6.FIND THE SUM DIGITS OF A GIVEN NUMBER.

INPUT;#include<stdio.h>

void main()

{int l,i,j,s;

printf("enter a number:");

scanf("%d",&i);

s=0;

l=i;

j=i%10;

for(j;i!=0;j=i%10)

{s=s+j;

i=i/10;}
printf("sum of digits of %d is %d",l,s);}

output;enter a number:123

sum of digits of 123 is 6

7)check whether a number is a palindrome or not

Input; #include <stdio.h>

int main()

{int i,x,n,sum;

printf("enter the number:");

scanf("%d",&x);

sum=0;

int z =x;

while (x!=0)

{n=x%10;

sum =(sum*10)+n;

x=x%10;}

if(z==sum)

{printf("the number is a palindrome");}

else

{printf("the number is not a palindrome");}

return 0;}

output; enter the number ;313

the number is a palindrome


8)check weather a number is prime or not.

ans)input;#include<stdio.h>

int main()

{int i,j;

printf("enter a number:");

scanf("%d",&i);

j=i-1;

for (j;j>=1;j--)

{if(j==1)

{printf("%d is a prime",i);

break;}

else if(i%j==0)

{printf("%d is not a prime",i);

break;};}

output; enter a number:5

5 is a prime.

9.PRINT THE PRIME NUBERS IN A GIVEN RANGE.

INPUT;#include<stdio.h>

int main (){

int i,j;

printf("enter the extrem value:");

scanf("%d,%d",&i,&j);
int k=i-1;

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

{k=i-1;

while(k>1)

if(i%k==0)

{printf("\n");

break;}

--k

if(k==1)

{printf("%d is a prime\n",i);}

return 0;}

OUTPUT;enter the extrem value:3,9

3 IS PRIME NUMBER

5 IS PRIME NUMBER

7 IS PRIME NUMBER

10)fibonacci series in a given range 1,1,2,3,5.


ans)input;

#include<stdio.h>

void main()

{int i,j,k;

printf("enter extreme values:");

scanf("%d,%d",&i,&j);

k=i;

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

{k=i-k;

printf("%d,",i);};}

output;

enter extreme values:1,6

1,1,2,3,5,

11)sum of series 1+2+3+4+..........+n

ans); input;

#include<stdio.h>

void main()

{int n,k,j;

printf("enter a number:");
scanf("%d",&n);

j=n;

k=0;

for(n;n>0;n--)

{k=k+n;

if(n==1)

{printf("sum of first %d natural numbers is %d",j,k);}};}

output;

enter a number:5

sum of first 5 natural numbers is 15.

12)check whether a number is Krishnamoorthi number

Ans)input;

include<stdio.h>

void main()

{int i,j,k,s=0,t=0;

printf("enter a number:");

scanf("%d",&i);

t=t+i;

for(i;i/10>=0;i=i/10)

{ k=1;

for(j=i%10;j>0;j--)

{k*=j;}

s=s+k;

if(i/10==0)

break;

}
if(s==t)

printf("it is krishna murthy number");

else

printf("it is not a krishna murthy number");

out put)

enter a number:1

it is krishna murthy number

output:/tmp/dlqqglpE0g.o

enter a number:1

it is krishna murthy number

13)check whether a number is Armstrong number

Input; #include <stdio.h>

#include <math.h>

int main() {

int n, N, remainder, result = 0;

printf("Enter the number: ");

scanf("%d", &n);

N = n;

int numberOfDigits = 0;

while (N != 0) {

N = N / 10;

++numberOfDigits;

}
N = n;

while (N != 0) {

remainder = N % 10;

result = result + pow(remainder, numberOfDigits);

N = N / 10;

if (result == n)

printf("%d is an Armstrong number\n", n);

else

printf("%d is not an Armstrong number\n", n);

return 0;

Output; Enter the number: 153

153 is an Armstrong number

14.)sum of series 1+x+x2/2!+x3/3!+x4/4!+........


ans)input:#include<stdio.h>

int main()

{float n,b=1,i,k,a=1,t;

printf("enter the value of n and till wher you need the series");

scanf("%f%f",&n,&t);

k=n;

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

{n=n*k/(b+1);

a=a+n;

b++;}

printf("sum of given number is %f\n",a+k);}

output;

enter the value of n and till wher you need the series3

300

sum of given number is 20.085539.

15)sum of series x-x3/3!+x5/5!-x7/7!+x9/9!......

input;#include<stdio.h>

int main()

{float a=0,c=1,x,b,n,i;

printf("enter the value of number u wnat and series till where u want");
scanf("%f%f",&x,&n);

b=x;

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

{a=a+b;

b=(-1*x*x*b)/((c+1)*(c+2));

c=c+2;}

printf("%f",a);}

output;

enter the value of number u wnat and series till where u want3

100

0.141120.

You might also like