0% found this document useful (0 votes)
27 views

Vraj Patel All Program

The document contains 19 code snippets demonstrating the use of user-defined functions (UDFs) in C programming with different combinations of arguments and return values. The snippets show functions for calculating the sum of two numbers, finding the sum of digits in a number, reversing a number, checking if a number is a palindrome, and checking if a number is prime.

Uploaded by

Harsh Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Vraj Patel All Program

The document contains 19 code snippets demonstrating the use of user-defined functions (UDFs) in C programming with different combinations of arguments and return values. The snippets show functions for calculating the sum of two numbers, finding the sum of digits in a number, reversing a number, checking if a number is a palindrome, and checking if a number is prime.

Uploaded by

Harsh Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

1.

//WAC program UD function sum of two values


//with NOT arguments and NOT return value

#include<stdio.h>

int sum ();

int main ()

clrscr();

sum ();

getch();

sum ()

int a,b;

printf("enter two number : ");

scanf("%d%d",&a,&b);

printf("sum of two value is %d",a+b);

}
2. //WAC program UD function sum of two values

//with arguments and NOT return value

#include<stdio.h>

int sum (int ,int );

int main ()

int a,b;

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

sum (a,b);

getch();

sum (int x,int y)

printf("sum of two value is %d",x+y);

}
3. //WAC program UD function sum of two values

//with argyument and return value

#include<stdio.h>

int sum (int ,int );

int main ()

int a,b;

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

printf("sum of two value is %d",sum (a,b));

getch();

sum (int x,int y)

return x+y;

}
4. //WAC program UD function sum of two values

//with no argyument and return value

#include<stdio.h>

int sum ();

int main ()

clrscr();

printf("sum of two value is %d",sum ());

getch();

sum ()

int a,b;

printf("enter two number : ");

scanf("%d%d",&a,&b);

return a+b;

}
5. //WAC program to find sum of each digits ( Using UDF )
//with argument and NOT return.

#include<stdio.h>

#include<conio.h>

int digit(int );

int main()

int n;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

digit(n);

getch();

int digit(int N)

int rem,sum=0,temp=N;

while(N>0)

{
rem=N%10;

sum=sum+rem;

N=N/10;

printf("%d : sum = %d",temp,sum);

}
6. //WAC program to find sum of each digits ( Using UDF )

// With argument and with return.

#include<stdio.h>

#include<conio.h>

int digit(int );

int main()

int n;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

printf("%d : sum = %d",n,digit(n));

getch();

int digit(int N)

int rem,sum=0,temp=N;

while(N>0)

rem=N%10;
sum=sum+rem;

N=N/10;

return sum;

}
7. //WAC program to find sum of each digits ( Using UDF )

//NOT argument and with return.

#include<stdio.h>

#include<conio.h>

int digit();

int main()

clrscr();

printf(" sum of digis = %d ",digit());

getch();

int digit()

int n,rem,sum=0;

printf("Enter number : ");

scanf("%d",&n);

while(n>0)

rem=n%10;

sum=sum+rem;
n=n/10;

return sum;

}
8. //WAC program to find sum of each digits ( Using UDF )

//NOT argument and NOT return.

#include<stdio.h>

#include<conio.h>

int digit();

int main()

clrscr();

digit();

getch();

int digit()

int n,rem,sum=0,temp;

printf("Enter number : ");

scanf("%d",&n);

temp=n;

while(n>0)

rem=n%10;
sum=sum+rem;

n=n/10;

printf("%d : sum = %d",temp,sum);

}
9. //WAC program to enter number and print its reverse
number ( Using UDF )
//with argument and NOT return.

#include<stdio.h>

#include<conio.h>

int rev(int );

int main()

int n;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

rev(n);

getch();

int rev(int N)

int rem,rev=0,temp=N;

while(N>0)
{

rem=N%10;

rev=rev*10+rem;

N=N/10;

printf("%d : revers num is %d",temp,rev);

}
10. //WAC program to enter number and print its revers number (Using
UDF)

// With argument and with return.

#include<stdio.h>

#include<conio.h>

int rev(int );

int main()

int n;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

printf("%d : revers num is %d",n,rev(n));

getch();

int rev(int N)

int rem,rev=0;

while(N>0)

{
rem=N%10;

rev=rev*10+rem;

N=N/10;

return rev;

}
11. //WAC program to enter number and print its revers number (
Using UDF )

//NOT argument and with return.

#include<stdio.h>

#include<conio.h>

int rev();

int main()

clrscr();

printf(" revers num is %d ",rev());

getch();

int rev()

int n,rem,rev=0;

printf("Enter number : ");

scanf("%d",&n);

while(n>0)

rem=n%10;
rev=rev*10+rem;

n=n/10;

return rev;

}
12. //WAC program to enter number and print its revers number (
Using UDF )

//NOT argument and NOT return.

#include<stdio.h>

#include<conio.h>

int rev();

int main()

clrscr();

rev();

getch();

int rev()

int n,rem,rev=0,temp;

printf("Enter number : ");

scanf("%d",&n);

temp=n;

while(n>0)

{
rem=n%10;

rev=rev*10+rem;

n=n/10;

printf("%d : revers num is %d",temp,rev);

}
13. //WAC program to enter number and chake given num
is palindrome or NOT ( Using UDF )
//with argument and NOT return.

#include<stdio.h>

#include<conio.h>

int pal(int );

int main()

int n;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

pal(n);

getch();

int pal(int N)

int rem,pal=0,temp=N;

while(N>0)
{

rem=N%10;

pal=pal*10+rem;

N=N/10;

if(temp==pal)

printf("A number is palindrem number ");

else

printf("A number is NOT palindrem number ");

}
14. //WAC program to enter number and chake given num is palindrem
or NOT ( Using UDF )

// With argument and with return.

#include<stdio.h>

#include<conio.h>

int pal(int );

int main()

int n,N;

clrscr();

printf("Enter number : ");

scanf("%d",&n);

N=pal(n);

if(N==0)

printf("A number is palindrem number ");

else

printf("A number is NOT palindrem number ");


}

getch();

int pal(int n)

int rem,pal=0,temp;

temp=n;

while(n>0)

rem=n%10;

pal=pal*10+rem;

n=n/10;

if(temp==pal)

return 0;

else

return 1;

}
15. //WAC program to enter number and chake given num is palindrem
or NOT ( Using UDF )

//NOT argument and with return.

#include<stdio.h>

#include<conio.h>

int pal();

int main()

clrscr();

if(pal()==0)

printf("A number is palindrem number ");

else

printf("A number is NOT palindrem number ");

getch();

int pal()

int rem,n,pal=0,temp;

printf("Enter number : ");

scanf("%d",&n);
temp=n;

while(n>0)

rem=n%10;

pal=pal*10+rem;

n=n/10;

if(temp==pal)

return 0;

else

return 1;

}
16. //WAC program to enter number and chake given num is palindrem
or NOT ( Using UDF )

//NOT argument and NOT return.

int pal();

int main()

clrscr();

pal();

getch();

int pal()

int rem,n,pal=0,temp;

printf("Enter number : ");

scanf("%d",&n);

temp=n;

while(n>0)

rem=n%10;

pal=pal*10+rem;
n=n/10;

if(temp==pal)

printf("A number is palindrem number ");

else

printf("A number is NOT palindrem number ");

}
17. //WAC program to enter number and chake given num
is prime or NOT ( Using UDF )
//with argument and NOT return.

#include<stdio.h>

#include<conio.h>

int count(int );

int main()

int n;

clrscr();

printf("Enter your number : ");

scanf("%d",&n);

count(n);

getch();

int count(int x)

int count=0,i;

for(i=1;i<=x;i++)
{

if(x%i==0)

count++;

if(count==2)

printf("Number is prime number");

else

printf("Number is NOT prime number");

}
18. //WAC program to enter number and chake given num is prime or
NOT ( Using UDF )

//With argument and With return.

#include<stdio.h>

#include<conio.h>

int count(int );

int main()

int n,N;

clrscr();

printf("Enter your number : ");

scanf("%d",&n);

N=count(n);

printf("\ncount = %d ",N);

getch();

int count(int n)

int count=0,i;
for(i=1;i<=n;i++)

if(n%i==0)

count++;

if(count==2){

printf("Number is prime number");

return n;

else{

printf("Number is NOT prime number");

return n;

}
19. //WAC program to enter number and chake given num is prime or
NOT ( Using UDF )

//With NOT argument and With return.

#include<stdio.h>

#include<conio.h>

int count();

int main()

clrscr();

printf("\ncount = %d ",count());

getch();

int count()

int count=0,i,n;

printf("Enter your number : ");

scanf("%d",&n);

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

if(n%i==0)
{

count++;

if(count==2){

printf("Number is prime number");

return n;

else{

printf("Number is NOT prime number");

return n;

}
20. //WAC program to enter number and chake given num is prime or
NOT ( Using UDF )

//With NOT argument and NOT return.

#include<stdio.h>

#include<conio.h>

int count();

int main()

clrscr();

count();

getch();

int count()

int count=0,i,n;

printf("Enter your number : ");

scanf("%d",&n);

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

if(n%i==0)
{

count++;

if(count==2)

printf("Number is prime number");

else

printf("Number is NOT prime number");

}
21. // WAC program to enter num.. and chake given num.. is
even or odd (Using UDF)
// With argument and NOT return.

# include <stdio.h>

# include <conio.h>

int ev_odd(int );

int main ()

int n;

clrscr();

printf(" Enter your number : ");

scanf("%d",&n);

ev_odd(n);

getch();

int ev_odd(int N)

{
if(N % 2 == 0)

printf(" Number is even number \n");

else

printf(" Number is odd number \n");

}
22. // WAC program to enter num.. and chake given num.. is even or
odd (Using UDF)

// With argument and return.

# include <stdio.h>

# include <conio.h>

int ev_odd(int );

int main ()

int n;

clrscr();

printf(" Enter your number : ");

scanf("%d",&n);

if(ev_odd(n) % 2 == 0)

printf(" Number is even number \n");

else
{

printf(" Number is odd number \n");

getch();

int ev_odd(int N)

if(N % 2 == 0)

return 0;

else

return 1;

}
23. // WAC program to enter num.. and chake given num.. is even or
odd (Using UDF)

// With NOT argument and return.

# include <stdio.h>

# include <conio.h>

int ev_odd();

int main ()

int n;

clrscr();

if(ev_odd() % 2 == 0)

printf(" Number is even number \n");

else

{
printf(" Number is odd number \n");

getch();

int ev_odd()

int N;

printf(" Enter your number : ");

scanf("%d",&N);

if(N % 2 == 0)

return 0;

else

return 1;

}
24. // WAC program to enter num.. and chake given num.. is even or
odd (Using UDF)

// With NOT argument and NOT return.

# include <stdio.h>

# include <conio.h>

int ev_odd();

int main ()

int n;

clrscr():

ev_odd();

getch();

int ev_odd()

int N;

printf(" Enter your number : ");


scanf("%d",&N);

if(N % 2 == 0)

printf(" Number is even number \n");

else

printf(" Number is odd number \n");

}
25. //WAC progrem to find factorial of given number (Using UDF)

//With argument and NOT return value

#include<stdio.h>

#include<conio.h>

int fact(int );

int main()

int i,n;

clrscr();

printf(" Enter Your Number : ");

scanf("%d",&n);

fact(n);

grtch();

int fact (int N)

int i,fact=1;

for(i=N;i>=1;i--)

{
fact=fact*i;

printf(" factorial is : %d ",fact);

}
26. //WAC progrem to find factorial of given number (Using UDF)

//With argument and return value

#include<stdio.h>

#include<conio.h>

int fact(int );

int main()

int i,n;

clrscr();

printf(" Enter Your Number : ");

scanf("%d",&n);

printf(" factorial is : %d ",fact(n));

getch();

int fact (int N)

int i,fact=1;

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

{
fact=fact*i;

return fact;

}
27. //WAC progrem to find factorial of given number (Using UDF)

//With NOT argument and return value

#include<stdio.h>

#include<conio.h>

int fact();

int main()

int i,n;

clrscr();

printf(" factorial is : %d ",fact());

getch();

int fact ()

int i,fact=1,N;

printf(" Enter Your Number : ");

scanf("%d",&N);

for(i=N;i>=1;i--)

{
fact=fact*i;

return fact;

}
28. //WAC progrem to find factorial of given number (Using UDF)

//With NOT argument and NOT return value

#include<stdio.h>

#include<conio.h>

int fact();

int main()

clrscr();

fact();

getch();

int fact ()

int i,fact=1,N;

printf(" Enter Your Number : ");

scanf("%d",&N);

for(i=N;i>=1;i--)

fact=fact*i;

}
printf(" factorial is : %d ",fact);

}
29. //WAC program UD function to find sum,sub,mul,div of two value

//with argyument and NOT return multiple value

#include<stdio.h>

int sum (int ,int );

int sub (int ,int );

int mul (int ,int );

float div (int ,int );

int main ()

int a,b;

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

sum(a,b);

sub(a,b);

mul(a,b);

div(a,b);

getch();

sum (int a,int b){


printf("sum of two value is %d \n",a+b);

sub(int a,int b){

printf("sub of two value is %d \n",a-b);

mul(int a,int b){

printf("mul of two value is %d \n",a*b);

float div (int a,int b){

printf("div of two value is %f \n",(float)a/b);

}
30. //WAC program UD function to find sum,sub,mul,div of two value

//with argyument and return multiple value

#include<stdio.h>

#include<conio.h>

int sum (int , int );

int sub (int , int );

int mul (int , int );

float div (int , int );

int main ()

int a,b;

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

printf("sum of two value is %d \n",sum (a,b));

printf("sub of two value is %d \n",sub (a,b));

printf("mul of two value is %d \n",mul (a,b));


printf("div of two value is %2f \n",div (a,b));

getch();

sum (int a,int b){

int W=a+b;

return W;

sub(int a,int b){

int X=a-b;

return X;

mul(int a,int b){

int Y=a*b;

return Y;

float div (int a,int b){


return (float)a/b;

}
31. //WAC program UD function to find sum,sub,mul,div of two value

//NOT argyument and return multiple value

#include<stdio.h>

int a,b;

int sum ();

int sub ();

int mul ();

float div ();

int main ()

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

printf("sum of two value is %d \n",sum ());

printf("sub of two value is %d \n",sub ());

printf("mul of two value is %d \n",mul ());

printf("div of two value is %2f \n",div ());

getch();

sum (){
return a+b;

sub(){

return a-b;

mul(){

return a*b;

float div (){

return (float)a/b;

}
32. //WAC program UD function to find sum,sub,mul,div of two value

//with no argyument and no return multiple value

#include<stdio.h>

int a,b;

int sum ();

int sub ();

int mul ();

float div ();

int main ()

clrscr();

sum ();

sub ();

mul ();

div ();

getch();

sum ()

printf("enter two number : ");


scanf("%d%d",&a,&b);

printf("sum of two value is %d \n",a+b);

sub(){

printf("sub of two value is %d\n",a-b);

mul(){

printf("mul of two value is %d\n",a*b);

float div (){

printf("div of two value is %2f\n",(float)a/b);

}
33. //WAC program UD function to find sum,sub,mul,div of two value
using switch case

#include<stdio.h>

#include<conio.h>

int sum (int , int );

int sub (int , int );

int mul (int , int );

float div (int , int );

int main ()

int a,b,N;

clrscr();

printf("enter two number : ");

scanf("%d%d",&a,&b);

printf("_____________________________________
___________");

printf("\n\t1. addition \n\t2. subbtraction \n\t3.


multiplication \n\t4. division\n");
printf("_____________________________________
___________");

printf("\n\nEnter your choise : ");

scanf("%d",&N);

switch (N)

case 1:sum (a,b);

break;

case 2:sub (a,b);

break;

case 3:mul (a,b);

break;

case 4:div (a,b);

break;

default:printf("wrong choice :(");

getch();

sum (int a,int b){


int W=a+b;

printf("\n\t->sum of two value is %d \n",W);

sub(int a,int b){

int X=a-b;

printf("\n\t->sub of two value is %d \n",X);

mul(int a,int b){

int Y=a*b;

printf("\n\t->mul of two value is %d \n",Y);

float div (int a,int b){

printf("\n\t->div of two value is %2f \n",(float)a/b);

}
34. // WAC program to find sum of first 10 odd-evan number

#include<stdio.h>

#include<conio.h>

int sum_odd_evan();

int main()

clrscr();

printf("-> sum of first 10 odd evan number :> \n\n");

sum_odd_evan();

getch();

int sum_odd_evan()

int i,s_odd=0,s_even=0;

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

if(i % 2 == 0)

{
s_even+=i;

else

s_odd+=i;

printf("\n\tsum of first 10 evan number :> %d \n",s_even);

printf("\n\tsum of first 10 odd number :> %d \n",s_odd);

You might also like