You are on page 1of 11

/*Practical No.

01
Title:Write a program to rotate values of a variable x,y,z such that x->y,->z,z->x.
Student name:Pranay Chandrakant Randive
Date:09/09/2019*/
#include<stdio.h>
int main(void)
{
int x,y,z;
printf("Enter three numbers to rotate \n");
scanf("%d %d %d", &x,&y,&z);
x=x+y+z;
y=x-y-z;
z=x-y-z;
x=x-y-z;
printf("After rotating values are x=%d, y=%d, z=%d", x,y,z);
return 0;
}

Output:
/*Practical No.02
Title:Write a program to find largest of three numbers using nested if statement.
Student name:-Pranay Chandrakant Randive
Date:-13-09-2019*/
#include <stdio.h>
int main(void)
{
int a,b,c;
printf("Enters the three numbers a,b,c\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("largest number=%d",a);
}
else
{
printf("largest number=%d",c);
}
}
else
{
if(b>c)
{
printf("largest number=%d",b);
}
else
{
printf("largest number=%d",c);
}
}
return 0;
}
Output:
/*Practical No.03
Title:Write a program to find factorial of a given number using for loop statement.
Student name:-Pranay Chandrakant Randive
Date:-16-09-2019*/

#include<stdio.h>
int main(void)
{
int num,i,fact=1;
printf("Enter the number of which factorial is to be calculate\n");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("factorial of given no.=%d",fact);
return 0;
}
/*Practical No.04
Title:Write a program to add digits of number.
Student name:Pranay Chandrakant Randive
Date:20/09/2019*/
#include<stdio.h>
int main(void)
{
int num,rem,sum=0;
printf("Enter a Number\n");
scanf("%d",&num);
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("Sum of digits of number= %d",sum);
return 0;
}
Output:
/*Program No.05
Title:Write a program to list prime numbers from 1 to 500 using For statement.
Student Name:Pranay Chandrakant Randive
Date:23/09/2019*/
#include<stdio.h>
int main(void)
{
int i,j,flag,count=0;
for(i=2;i<=500;i++)
{
flag=1;
for(j=2;j<i;j++)
{
if(i%j==0)
flag=0;
}
if(flag==1)
{
printf("%d\t", i);
count++;
}
}
printf("\nTotal prime numbers are=%d", count);
return 0;
}
Output:
/*Practical No.06
Title:Write a program to test whether the number is palindrome using do-while statement.
Student Name:Pranay Chandrakant Randive
Date:30/09/2019*/
#include<stdio.h>
int main(void)
{
int n,sum=0,temp,rem;
printf("Enter the number to be checked\n");
scanf("%d",&n);
temp=n;
do
{
rem=n%10;
sum=sum*10+rem;
n=n/10;
}
while(n>0);
if(sum==temp)
{
printf("Number is Palindrome Number");
}
else
{
printf("It is not a Palindrome Number");
}
return 0;
}
Output:
/*Practical No.07
Title:Write a program to test whether the given number is Armstrong number using if and go-
to statement.
Student name:Pranay Chandrakant Randive
Date: 30/09/2019*/
#include<stdio.h>
int main(void)
{
int num,sum=0,rem,temp;
printf("Enter the Number\n");
scanf("%d",&num);
temp=num;
display : if(num>0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
goto display;
}
if(temp==sum)
{
printf("It is an Armstrong Number");
}
else
{
printf("not armstrong");
}
return 0;
}
Output:

You might also like