source file name: recurfn.C #include<stdio.h> int n=10; int main() { if(n>0) { printf("%d ",n); n--; main(); } return 0; } output: 10 9 8 7 6 5 4 3 2 1
Read more12) Write a program that convert Decimal number into Roman equivalent using function.
Write a general-purpose function to convert any given year into its roman equivalent. The following table shows the roman equivalents of decimal numbers. Decimal Roman Decimal Roman Decimal Roman 1 I 5 V 10 X 50 L 100 C 500 D 1000 M Example: Roman equivalent of 1988 is MDCCCCLXXXVIII Roman equivalent of 1525 is MDX…
Read more11) Write a program that obtain the prime factors of given number using Function.
A positive integer is entered through the keyboard. Write a function to obtain the prime factors of this number . for example: Prime factors of 24 are 2,2,2 and 3 and whereas prime factors of 35 are 5 and 7. source file name: PrimeFactors.C void primefactor(int n) { int d; d=2; while(d<=n) { if(n%d==0) { printf(&q…
Read more10) Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers using function.
Problem Solution The formula which is used in this program is mean = average of the numbers. variance = (summation( ( Xi – average of numbers) * ( Xi – average of numbers)) ) / Total no of elements. where i = 1 to N here N is the total no of elements. Standard deviation = Square root of the variance. #inc…
Read more9) Write a program to add first Five terms of the following series using a function. 1/1! + 2/2! + 3/3! +4/4!+5/5! .
source file name: factseries.C int recfact(int n) { int f=1; if(n==0) return 1; else f=n*recfact(n-1); return f; } void main() { int n; float fv,sum=0; clrscr(); for(n=1;n<=5;n++) { fv=recfact(n); sum=sum+(n/fv); } printf(" factorial series sum: %f ",sum); getch(); } output: factorial series sum: 2.7…
Read more8) Write a program using user-defined functions that will determine the length, slope and the y-intercept of a line where end points are given.
source file name: LineSlope.C #include<math.h> void length(int x1, int y1, int x2, int y2) { int len; len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); printf(" \n Length of Line=%d ",len); } int slope(int x1, int y1, int x2, int y2) { int m; m=(y2-y1)/(x2-x1); printf("\n Slope=%d",m); return m; …
Read more7) Write a program that finds Maximum from 2 numbers using user defined function.
source file name: MaxFun.C int max(int m, int n) // declaration and definition { int res; if(m>n) res=m; else res=n; return res; } void main() { int a,b; int result; clrscr(); printf("enter 2 numbers: "); scanf("%d%d",&a,&b); result= max(a,b); // calling function printf(" max…
Read more6) Write a C program that finds sum of digits of a number using Recursive function.
source code name: RECSUM.C #include<stdio.h> int sumrec(int n) { int sum=0; int d; d=n%10; sum=sum+d; if(n==0) return 0; else { sum=sum+sumrec(n/10); } return sum; } int main() { int n,s; //clrscr(); printf(" enter any no: \n"); scanf("%d",&n); s=sumrec(n); printf(" sum of digits: …
Read moresource code: recfact.c #include<stdio.h> int recfact(int n) { int f=1; if(n==0) return 1; else f=n*recfact(n-1); return f; } int main() { int n,fv; //clrscr(); printf(" enter any no: \n"); scanf("%d",&n); fv=recfact(n); printf(" factorial value: %d ",fv); //getch(); return 0…
Read morevoid fact(int n) { int f=1; for(;n>0;n--) f=f*n; printf(" factorial value: %d ",f); } void main() { int n,f; clrscr(); printf(" enter any no: \n"); scanf("%d",&n); fact(n); getch(); } output: enter any no: 5 factorial value: 120
Read moresource code: primefn.c void prime(int n) { int d=2; while(d<n) { if(n%d==0) { break; } else d++; } if(n==d) printf(" %d ",n); } void main() { int k; clrscr(); printf(" function for prime numbers 2 to 100 \n"); for(k=2;k<100;k++) prime(k); getch(); } output: function for prime numbers 2 to…
Read more2) Write a C program that displays Armstrong numbers between 100 to 999 using Function.
source file name: Armstrong.C #include<stdio.h> int main() { void armstrong(int); int n; //clrscr(); for(n=100;n<1000;n++) { armstrong(n); } //getch(); return 0; } void armstrong(int n) { int d,sum=0,t; t=n; while(n>0) { d=n%10; sum=sum+(d*d*d); n=n/10; } if(…
Read more1) Write a C program that displays given year number is leap or not using Function.
#include<stdio.h> int main() { void leapy(int); int y; //clrscr(); printf("\n\tEnter any year"); scanf("%d",&y); leapy(y); //getch(); return 0; } void leapy(int n) { if (n%4==0) printf("\n\tGiven year is leap year"); else printf("Not leap ye…
Read more