NAME:Bilal
Mehdi
Roll no: SP20-BSE-019
PF Assignment # 4
Problem: Write a function to interchange the content of two variables.
#include<stdio.h>
void swap(int *,int *);
int main()
{
int a,b;
printf("Function : swap two numbers using function :\n");
printf("Input 1st number : ");
scanf("%d",&a);
printf("Input 2nd number : ");
scanf("%d",&b);
printf("Before swapping: a= %d, b= %d \n",a,b);
swap(&a,&b);
printf("\nAfter swapping: a= %d, b= %d \n",a,b);
return 0;
}
void swap(int *x,int *y)
{
int c;
c = *x;
*x=*y;
*y=c;
}
Problem: Write a function to perform the left circular shift operation
on four variable.
#include <stdio.h>
void leftsp(int *a, int *b, int *c, int *d);
int main() {
int a, b, c, d;
printf("Enter a, b c d respectively:\n");
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("Value before swapping:\n");
printf("a = %d \nb = %d \nc = %d\n d = %d\n", a, b, c,d);
leftsp(&a, &b, &c, &d);
printf("Value after swapping:\n");
printf("a = %d \nb = %d \nc = %d \nd = %d\n", a, b, c,d);
return 0;
void leftsp(int *w, int *x, int *y, int *z) {
int t;
t = *w;
*w = *x;
*x = *y;
*y = *z;
*z = t;
Problem: Write a function to perform the right circular shift
operation on four variable.
#include <stdio.h>
void rightsp(int *a, int *b, int *c, int *d);
int main() {
int a, b, c, d;
printf("Enter a, b c d respectively:\n");
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("Value before swapping:\n");
printf("a = %d \nb = %d \nc = %d\nd = %d\n", a, b, c,d);
rightsp(&a, &b, &c, &d);
printf("Value after swapping:\n");
printf("a = %d \nb = %d \nc = %d \nd = %d\n", a, b, c,d);
return 0;
void rightsp(int *w, int *x, int *y, int *z) {
int t;
t = *z;
*z = *y;
*y = *x;
*x = *w;
*w = t;
Problem: Write a function which takes two values (upper limit and
lower limit) and prints all prime number between upper limit and lower
limit.
#include <stdio.h>
int primen(int y);
int main() {
int a, b, c, d;
printf("Enter two positive integers: \n");
scanf("%d %d", &a, &b);
printf("Prime numbers between %d and %d are:\n", a,b);
for (c = a+1; c < b; ++c)
d = primen(c);
if (d == 1)
printf("%d ", c);
return 0;
int primen(int y)
int x, d= 1;
for (x = 2; x <= y / 2; ++x) {
if (y % x == 0) {
d = 0;
break;
return d;
Problem: Write a function which returns one if number is Armstrong
otherwise zero. However, the return type of the function must be void.
#include<stdio.h>
int isArmstrong(int number)
int lastDigit = 0;
int power = 0;
int sum = 0;
int n = number;
while(n!=0) {
lastDigit = n % 10;
power = lastDigit*lastDigit*lastDigit;
sum += power;
n /= 10;
if(sum == number) return 0;
else return 1;
int main()
int number;
printf("Enter number: ");
scanf("%d",&number);
if(isArmstrong(number) == 0)
printf("%d is an Armstrong number.\n", number);
else
printf("%d is not an Armstrong number.", number);
return 0;
Problem: Write a function that takes a decimal value as input and
returns a binary value.
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10],b,c;
system ("cls");
printf("Enter the number to convert: ");
scanf("%d",&b);
for(c=0;b>0;c++)
a[c]=b%2;
b=b/2;
}
printf("\nBinary of Given Number is=");
for(c=c-1;c>=0;c--)
printf("%d",a[c]);
return 0;
Problem: Write a function that takes a very large integer value (at
least 40 digits long) and prints the sum of digits.
Problem: Write a function that takes two integer values as input and
returns the GCD of passed values.
#include<stdio.h>
int gcd(int a, int b);
int main()
int num1, num2;
printf("Enter two numbers : ");
scanf("%d %d",&num1, &num2);
int result = gcd(num1, num2);
printf("The GCD of %d and %d = %d", num1, num2, result);
return 0;
}
Problem: Write a program in C to find the sum of the series
1!/1+2!/2+3!/3+4!/4+5!/5 using the function.
#include <stdio.h>
int fact(int x);
main()
int s;
s=fact(1)/1+fact(2)/2+fact(3)/3+fact(4)/4+fact(5)/5;
printf("Function : find the sum of 1!/1+2!/2+3!/3+4!/4+5!/5 :\n");
printf("The sum of the series is : %d\n\n",s);
int fact(int x)
int y=0,z=1;
while(y<=x-1)
z=z+z*y;
y++;
}
return z;
Problem: Write a C program to find diameter, circumference, and area
of circle using functions. Use three function one for each.
#include <stdio.h>
int diameter(int radius);
int circumference(int radius);
int area(int radius);
int main()
float r, d, c, a;
printf("Enter radius of circle:\n");
scanf("%f", &r);
a=area(r);
d=diameter(r);
c=circumference(r);
printf("Area of the circle = %f\n", a);
printf("Diameter of the circle = %f\n", d);
printf("Circumference of the circle = %f\n", c);
return 0;
int diameter(int r)
return (2 * r);
int circumference(int r)
return (2 * 3.14 * r);
int area(int r)
return (3.14 * r * r);
}
Problem: Write a C program to find sum of all even and odd numbers in
given range. Use single function and result should be accessible in main
function.
#include <stdio.h>
int sumevenodd(int a, int b);
int main()
int a, b, sum;
printf("Enter upper limit: ");
scanf("%d", &b);
printf("Enter lower limit: ");
scanf("%d", &a);
printf("Sum of even/odd numbers between %d to %d = %d\n", a, b,
sumevenodd(a, b));
return 0;
int sumevenodd(int a, int b)
{
if(a >b)
return 0;
else
return (a + sumevenodd(a + 2, b));
Problem: Write a program which takes a character value as an input
and return the capital Letter if the input value is small letter, return
the small letter if the input value is capital letter, otherwise return
the same value. Call the function three time in main with different
inputs and print the received value.