Professional Documents
Culture Documents
Cs 01
Cs 01
Code:
#include<stdio.h>
int main()
{
printf("Hello World");
return 0;
}
Output:
Q-2: Write a program to print your name.
Code-
#include<stdio.h>
int main()
{
printf("Akash Roy");
return 0;
}
Output:
Lab-2
Code:-
#include<stdio.h>
int main()
{
int a,b;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
printf("The addition of %d and %d is %d\n",a,b,a+b);
printf("The substraction of %d and %d is %d\n",a,b,a-b);
printf("The multiplication of %d and %d is %d\n",a,b,a*b);
printf("The division of %d and %d is %d\n",a,b,a/b);
printf("The modulo of %d and %d is %d",a,b,a%b);
return 0;
}
Output:-
Q-2: Write a program to accept the radius of a circle, find its
area as well as perimeter.
Code:-
#include<stdio.h>
int main()
{
int r,area,peri;
printf("Enter radius:");
scanf("%d",&r);
area=3.14*r*r;
peri=2*3.14*r;
printf("The area of the circle is %d\n",area);
printf("The perimeter of the circle is %d",peri);
return 0;
}
Output:-
Lab-3
Q-1 : Write a program to accept two number from user and
swap that two number using third variable.
Code:-
#include<stdio.h>
int main()
{
int num1,num2,temp;
printf("Enter 1st number:");
scanf("%d",&num1);
printf("Enter 2nd number:");
scanf("%d",&num2);
printf("Before swapping the 1st number is %d and the
second number is %d\n",num1,num2);
temp=num1;
num1=num2;
num2=temp;
printf("After swapping the 1st number is %d and the
second number is %d",num1,num2);
return 0;}
Output:-
Q-2: Write a program to accept two number from user and
swap that two number without third variable.
Code:-
#include<stdio.h>
int main()
{
int num1,num2;
printf("Enter 1st number:");
scanf("%d",&num1);
printf("Enter 2nd number:");
scanf("%d",&num2);
printf("Before swapping the 1st number is %d and the
second number is %d\n",num1,num2);
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
printf("After swapping the 1st number is %d and the
second number is %d",num1,num2);
return 0;
}
Output:-
Lab-4
#include<stdio.h>
int main()
{
int num;
printf("Enter a number:");
scanf("%d",&num);
if(num%2==0){
printf("The number is even");
}
else{
printf("The number is odd");
}
return 0;
}
Output:
Q-2: Write a program to accept three number from user and
find the largest number.
Code:
#include<stdio.h>
int main()
{
int num1,num2,num3;
printf("Enter three number:");
scanf("%d%d%d",&num1,&num2,&num3);
if(num1>=num2 && num1>=num3){
printf("The largest number is %d",num1);
}
else if(num2>=num1 && num2>=num3){
printf("The largest number is %d",num2);
}
else{
printf("The largest number is %d",num3);
}
return 0;
}
Output:
Lab-5
Q-1:- Wap to accept two number from the user and
print it in acending order.
Code-
#include<stdio.h>
int main()
{
int num1,num2,i;
if(num1>num2){
for(i=num2;i<=num1;i++)
printf("%d\n",i);
}
else{
for(i=num1;i<=num2;i++)
printf("%d\n",i);
}
}
Output:
Q-2:-
Wap to accept a positive number and find its factorial.
Code:-
#include<stdio.h>
int main()
{
intnum,i,fact=1;
printf("Enter a positive number:");
scanf("%d",&num);
if(num>0){
for(i=num;i>=1;i--){
fact*=i;
}
printf("The factorial of %d is %d",num,fact);
}
else{
printf("Enter a positive number!!!!!");
}
}
Output:
Q-3:- Wap to accept a positive number and check
the number is prime or not.
Code:-
#include<stdio.h>
int main()
{
intn,i,m=0,flag=0;
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf("Number is not prime");
flag=1;
break;
} }
if(flag==0){
printf("Number is prime");
return 0;
}
}
Output:-
Lab-6
Q-1:- Wap to accept a positive number and
find its reverse.
Code:-
#include<stdio.h>
int main()
{
int n, reverse = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
if(n>0){
while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", reverse);
}
else{
printf(“Enter a positive number”);
}
return 0;
}
Output:-
Q-2:- Wap to accept a positive number and
check the number is Armstrong or not.
Code:-
#include<stdio.h>
int main()
{
intn,num,r, ans=0;
printf("Enter an integer: ");
scanf("%d", &n);
num=n;
if(n>0){
while (n != 0) {
r = n % 10;
ans = ans+r*r*r;
n /= 10;
}
if(ans==num){
printf("%d is an Armstrong
number.",num);
}
else{
printf("%d is not an Armstrong
number.",num);
}
}
else{
printf("Enter a positive number!!!");
}
return 0;
}
Output:-
Q-3:- Wap to accept a positive number and
check the number is perfect or not.
Code:-
#include<stdio.h>
int main()
{
intnum, count = 1, sum = 0;
printf("Enter a number\n");
scanf("%d", &num);
while(count <num)
{
if(num%count == 0)
{
sum = sum + count;
}
count++;
}
if(sum == num)
{
printf("\n%d is a perfect number\n", num);
}
else
{
printf("\n%d is not a perfect number\n", num);
}
return 0;
}
Output:-