c Programs | Computing Infrastructure | Computer Libraries

# C Programs 10.Oct.

2010

ASSIGNMENT ON C PROGRAMING

Submitted by: Chinnu Chandran S1 M.C.A Roll No:06

1

C Programs 10.Oct.2010

INDEX
&RQWHQW To display n even numbers
Multiplication Table of a given number To print factorial of a number Print the series 1+1/2+1/3«««««+1/n Find the sum and average of n numbers Program for finding x to the power n Accept age & sex of n students & display the average age of¶Male & female Find highest & smallest from n numbers Fibonacci series upto a given number Find the sum of digits of a number Find Amstrong number s from n to m Program to check palindrome whether a number is

3DJH1R 03
04 06 07 09 10 12

15 17 19 20 22

Program to find palindrome numbers between 2 limits  Write a program to display n even numbers

24

2

i.C Programs 10.ctr). i=1. scanf("%d".h> main() { int n.Oct. i++.2010 //Program Id : neven.c //Author : Chinnu Chandran //Date : 07.ctr=1. } getch().10.2010 //Time : 3:15 p. } ctr++.&n). } 3 . while(i<=n) { if(ctr%2==0) { printf("%d\t". printf("Enter the limits\n").m //Remarks :first n even numbers #include<stdio.

m //Remarks :find the multiplication table of a number #include<stdio. 4 . printf("Enter the number to find multiplication\n").c //Author : Chinnu Chandran //Date : 07.2010 Output :  Write a program to find multiplication table of a given number //Program Id : multi.h> main() { int i =1.n.m.10.2010 //Time : 4:15 p.C Programs 10.Oct.

n).i. printf("Enter the limits\n").&n). i++. scanf("%d". while(i<=m) { printf("\n%d*%d=%d".Oct. } getch().i*n). printf("Multiplication Table of %d is: \n".2010 scanf("%d".C Programs 10.&m). } Output:  Write a program to print factorial of a number 5 .n.

C Programs 10. i++. scanf("%d".Oct.&no).m //Remarks :find the factorial of a given number #include<stdio.fact=1. getch().fact).2010 //Program Id : fact. } printf("Factorial = %d". } Output : 6 .10.i=1. printf("Enter a number\t").c //Author : Chinnu Chandran //Date : 08.h> main() { int no.2010 //Time : 1:45 p. while(i<=no) { fact = fact * i.

m //Remarks : find the sum of the series 1+1/2+1/3..2010  Write a program to print the series 1+1/2+1/3««+1/n //Program Id : series.10..+1/10 #include<stdio.h> main() { 7 .2010 //Time : 7:40 p.C Programs 10..Oct.c //Author : Chinnu Chandran //Date : 08.

&n).sum).n. i++.2010 float sum=0. scanf("%f". while(i<=n) { sum =sum+1/i. printf("Enter the limit \t"). getch(). } printf("Sum of the series %f". } Output : 8 .Oct.C Programs 10.i=1.

c //Author : Chinnu Chandran //Date : 08. printf("Enter the limits\n").&n). sum = sum+num.m //Remarks : find the sum and average of n numbers #include<stdio.num. while(i<=n) { scanf("%d".h> main() { float avg = 0. i++.10.2010  Write a program to find the sum and average of n numbers //Program Id : avgnsum. int n.C Programs 10.2010 //Time : 8:12 p.i=1.sum=0. 9 . printf("Enter the numbers\n"). scanf("%d".Oct.&num).

} Output :  Write a program for finding x to the power n //Program Id : powerxn. printf("\nSum = %d".Oct.avg).sum).2010 } avg = (float)sum/n.c //Author : Chinnu Chandran 10 . getch().C Programs 10. printf("Average = %f".

while(i<=n) { p=p*x.p=1.Oct. i++.2010 //Date : 08.n.&x.m //Remarks : find x to the power n #include<stdio.C Programs 10. printf("Enter the values for x & n\n"). getch().10.i=1. } 11 .&n).h> main() { int x.p). } printf("The result is %d".2010 //Time : 9:19 p. scanf("%d\t%d".

c //Author : Chinnu Chandran //Date : 09.h> 12 . //Program Id : age.Oct.C Programs 10.2010 Output :  Write a program to accept age & sex of n students & display the average age of Male & female.10.2010 //Time : 8:19 a.m //Remarks : accept age & sex of n students & display average age of males & females #include<stdio.

&age).&s). } 13 .C Programs 10. mage=fage=0.fage.f.age. scanf("%d". while(i<n) { scanf("%d". printf("Enter the age and sex (m/f)\n").&n). float avgm. mage=mage+age. char s. printf("Enter the limits\n"). m=f=0.2010 main() { int n.Oct. if(s=='m'||s=='M') { m=m+1.mage. fflush(stdin).i=0.m.avgf. scanf("%c".

avgf=(float)fage/f.avgf).C Programs 10. printf("\nAverage age of females = %f". printf("Average age of males = %f".Oct. } avgm=(float)mage/m. fage=fage+age. } i++.avgm).2010 else if(s=='f'||s=='F') { f=f+1. } Output : 14 . getch().

C Programs 10.num.2010  Write a program to find lowest & highest of n given numbers //Program Id : minnmax. 15 .2010 //Time : 8:45 a.Oct.min=0.m //Remarks : find highest & smallest of n numbers #include<stdio.h> main() { int n.10.c //Author : Chinnu Chandran //Date : 09.max=0.i=1.

printf("\nLargest = %d".Oct. i++. scanf("%d". printf("Enter the number\n"). if(num>max) max=num. while(i<=n-1) { scanf("%d". } Output : 16 . if(num<min) min = num.C Programs 10.&num). getch().min).2010 printf("Enter the limit\n").&n). scanf("%d".&num). } printf("Smallest = %d".max). min=max=num.

h> main() 17 .2010  Write a program to find fibonacci series upto a given number. //Program Id : fibo.14 p.c //Author : Chinnu Chandran //Date : 09.m //Remarks : fibonaccic series #include<stdio.C Programs 10.10.2010 //Time : 12.Oct.

t).&n). } getch().C Programs 10. f=s. printf("Enter the number\n").f. i++. printf("The fibonaccic series are \n").Oct.t. } Output : 18 .2010 { int i=3.f. printf("%d\n%d".s.n. s=t.s). printf("\n%d". scanf("%d". while(i<n) { t=f+s. f=s=1.

c //Author : Chinnu Chandran //Date : 09.10.30 p.Oct.2010 //Time : 12.m //Remarks : to find the sum of digits #include<stdio.2010  Write a program to find the sum of digits of a number //Program Id : sumofdigits.C Programs 10.h> 19 .

getch(). while(n!=0) { r = n%10. } Output: 20 .&n).r. printf("Enter any number\n"). sum=sum+r.2010 main() { int n. scanf("%d". } printf("The result is %d\n".sum).C Programs 10.sum=0.Oct. n=n/10.

h> main() { int m.2010  Write a program to find amstrong number s from n to m.i.r.num.C Programs 10.m //Remarks : Pgm to print armstrong numbers from m to n #include<stdio.10.Oct. //Program Id : amstrong. 21 .sum.c //Author : Chinnu Chandran //Date : 10.c.n.2010 //Time : 4:19 p.

2010 printf("Enter the limits\n"). sum=sum+c. printf("Armstrong numbers from %d to %d are \n". c=r*r*r. i++.&m.n). } if(sum==i) printf("\n%d".m.C Programs 10. } getch(). while(i<=n) { num=i. while(num!=0) { r=num%10. num=num/10.Oct.i). sum=0. 22 . scanf("%d%d". i=m.&n).

m //Remarks : Pgm to check whether a number is palindrome or not 23 .10.C Programs 10.c //Author : Chinnu Chandran //Date : 10.2010 //Time : 6:47 p.Oct.2010 } Output :  Write a program to check whether the given number is palindrome or not //Program Id : palindrome.

h> main() { int num.2010 #include<stdio.Oct.C Programs 10.&num). } else { printf("Number is not Palindrome"). printf("Enter the number : "). } 24 . } if(rev==i) { printf("The number is Palindrome"). num=num/10. scanf("%d". i=num.i. while(num!=0) { rev=rev*10+num%10.rev=0.

c //Author : Chinnu Chandran //Date : 10.m //Remarks : Pgm to print Palindrome numbers from m to n 25 .10.Oct.C Programs 10. } Output:  Write a program to print palindrome numbers between 2 limits //Program Id : Npalindrome.2010 //Time : 6:56 p.2010 getch().

r.Oct. } if(rev==i) printf("\n%d".2010 #include<stdio.i). while(i<=n) { num=i.m. i++. printf("Enter the limits\n").c.i.n. rev=0.rev. printf("Palindrome numbers from %d to %d are \n". 26 .C Programs 10. i=m. scanf("%d%d". while(num!=0) { rev=rev*10+num%10.n).num.h> main() { int m.&m. num=num/10.&n).

Oct.C Programs 10.2010 } getch(). } Output : 27 .

Oct.2010 28 .C Programs 10.