0% found this document useful (0 votes)
11 views5 pages

Shubham Kumar (Btech Cse 2nd Sem)

None

Uploaded by

karan chaurasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Shubham Kumar (Btech Cse 2nd Sem)

None

Uploaded by

karan chaurasia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name:Shubham Kumar.

Semester:2nd
Roll No:10000119044 Course:B.Tech(C.S.E)

ASSIGNMENT:3

Question 1:
//program to find factorial
#include<stdio.h>
int main()
{
int n,fact=1,i;
printf("Enter a number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("the factorial of the number is:%d",fact);
return 0;
}

OUTPUT:
Enter a number:6
the factorial of the number is:720

Question 2:
//program to check if palindrome or not
#include<stdio.h>
int main()
{
int num,rev=0,num1,num2;
printf("Enter a number:");
scanf("%d",&num);
num1=num;
while(num>0)
{
num2=num%10;
rev=(rev*10)+num2;
num=num/10;
}
if(rev==num1)
printf("Number is Palindrome");
else
printf("Number is not Palindrome");
return 0;
}

OUTPUT:
Enter a number:121
Number is Palindrome

Enter a number:123
Number is not Palindrome

Question 3:
//program to check whether a number is Armstrong or not
#include<stdio.h>
#include<math.h>
int main()
{
int num,sum=0,num2,num1,d=0,n=0;
printf("Enter a number:");
scanf("%d",&num);
n=num;
while(n!=0)
{
n=n/10;
++d;
}
n=num;
while(n!=0)
{
num2=n%10;
sum=sum+pow(num2,d);
n=n/10;
}
if(sum==num)
printf("The number is armstrong");
else
printf("The number is not armstrong");
return 0;}

OUTPUT:
Enter a number: 371
The number is armstrong

Enter a number:1634
The number is armstrong

Question 4:
//program to print all the prime nos between 50 and 150
#include<stdio.h>
int main()
{
int i,j,c=0;
printf("The prime numbers are: \n");
for(i=51;i<150;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
{
printf("%d",i);
printf("\n");
}
c=0;
}
return 0;
}

OUTPUT:
The prime numbers are:
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149

Question 5:
//program to print the given patterns
#include<stdio.h>
int main()
{
int choice,i,j;
printf("Enter your choice (1 or 2):");
scanf("%d",&choice);
switch(choice)
{
case 1:for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
break;
case 2: for(i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
printf("%d",i);}
printf("\n");
}
break;
default: printf("Wrong choice");
}
return 0;
}

OUTPUT:

Enter your choice (1 or 2):1


1
12
123
1234
12345

Enter your choice (1 or 2):2


1
22
333
4444
55555

You might also like