Functions in C Programming

Functions

WAP in C to check whether the number entered by user is armstrong or not by
using function

[c] #include
#include
#include

int arm(int);
void main()
{
int x;
int y;
clrscr();
printf(“\nEnter a number=”);
scanf(“%d”,&x);
y=arm(x);
if(y==x)
{
printf(“\nThe number is armstrong”);
}
else
{
printf(“\nThe number is n’t armstrong”);
}
getch();
}

int arm(int a)
{
int r,sum=0;
while(a>0)
{
r=a%10;
sum=sum+pow(r,3);
a=a/10;
}
return sum;
}
[/c]

WAP in C by using function to print the fibonacci series upon the user choice

[c] #include
#include

void fibo(int);
void main()
{
int a;
clrscr();
printf(“\nUpto what terms do you want to print the series=”);
scanf(“%d”,&a);
fibo(a);
getch();
}

void fibo(int x)
{
int i;
int f0=0,f1=1,f2;
for(i=0;i

WAP in C to check whether the number entered by user is prime or not by using function

[c] #include
#include
int prime(int);
void main()
{
int a;
int b;
clrscr();
printf(“\nEnter a number=”);
scanf(“%d”,&a);
b=prime(a);
{
if(b==1)
{
printf(“\nThe number is prime”);
}
else
{
printf(“\nThe number isn’t prime”);
}
}
getch();
}

int prime(int x)
{
int i;
clrscr();
for(i=2;i

This entry was posted in Uncategorized. Bookmark the permalink.

3 thoughts on “Functions in C Programming

  1. Ralph Nectar says:

    Hey! I am interested to know about more topics on pointer and array.I found it more difficult to understand. Could you please upload some tutorial videos on youtube? I want to see more tutorial solutions.

Leave a Reply