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

Assignment 2

The document contains multiple C programs that perform various mathematical operations, including finding the GCD of two numbers, checking for palindromes, calculating factorials, finding factors, summing and multiplying digits of a number, reversing a number, converting digits to words, and identifying the first and last digits of a number. Each program prompts the user for input and displays the result of the computation. The code snippets demonstrate basic control structures and arithmetic operations in C.

Uploaded by

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

Assignment 2

The document contains multiple C programs that perform various mathematical operations, including finding the GCD of two numbers, checking for palindromes, calculating factorials, finding factors, summing and multiplying digits of a number, reversing a number, converting digits to words, and identifying the first and last digits of a number. Each program prompts the user for input and displays the result of the computation. The code snippets demonstrate basic control structures and arithmetic operations in C.

Uploaded by

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

D:\c language\palindrom.

c 1
// to find gcd of numbers
#include<stdio.h>
void main()
{
int n1;
int n2;
int c=0;
int m=0;
int g=0;
printf("Enter first number");
scanf("%d",&n1);
printf("Enter second number");
scanf("%d",&n2);
m=n1<n2?n1:n2;
for(c=1;c<=m;c++)
{
if(n1%c==0 && n1%c==0)
{
g=c;
}
}
printf("%d",g);
}
C:\Users\sunil\OneDrive\Desktop\Assignment 2\pallindrom.c 1
//pallindrom program
#include<stdio.h>
void main()
{
int n;
int temp;
printf("Enter the value of n");
scanf("%d",&n);
temp=n; //so at if condition we can use the first value of n
int ans=0;
int rem;

while(n%10>0)
{
rem=n%10;
ans=ans*10+rem;
n=n/10; //to remove the laast number as it work is over
}

if(temp==ans)
{
printf("Number is palindrone %d",ans);
}
else
{
printf("Number is not palindrome");
}

}
D:\c language\factorial.c 1
//factorials
#include<stdio.h>
void main()
{
int n;
int c=0;
int f=1;
printf("Enter teh value of n");
scanf("%d",&n);
for(c=1;c<=n/2;c++)
{
f=f*c;
}

printf("%d is factorial of %d",f,n);

}
c:\Users\sunil\OneDrive\documents\visual studio 2012...\ConsoleApplication36\ConsoleApplication36\factors.c 1
#include<stdio.h>
void main()
{
int n;
int c=0;
printf("enter the value");
scanf("%d",&n);
for(c=1;c<=n/2;c++)
{
if(n%c==0)
{
printf("%d\n",c);
}

}
}
D:\c language\numbersum.c 1
//sum of given numbers
#include<stdio.h>
void main()
{
int ans=0;
int rem;
int n;
printf("Enter the value of n");
scanf("%d",&n);

while(rem>0)
{
rem=n%10;
ans=ans+rem;
n=n/10;
}
printf("%d",ans);

}
D:\c language\numbersum.c 1
//multiplication of given numbers
#include<stdio.h>
void main()
{
int ans=1;
int rem;
int n;
printf("Enter the value of n");
scanf("%d",&n);

while(n%10>0)
{
rem=n%10;
ans=ans*rem;

n=n/10;
}
printf("%d",ans);

}
D:\c language\numbersum.c 1
//reverse of given numbers
#include<stdio.h>
void main()
{
int ans=0;
int rem;
int n;
printf("Enter the value of n");
scanf("%d",&n);

while(n%10>0)
{
rem=n%10;
ans=ans*10+rem;

n=n/10;
}
printf("%d",ans);

}
D:\c language\wordnumber.c 1
#include<stdio.h>
void main()
{
int n;
int rev=0;
printf("Enter the value of n");
scanf("%d",&n);
int rem;
while(n>0)
{
rem=n%10;
rev=(rev*10)+rem;
n=n/10;

}
n=rev;
while(n>0)
{
rem=n%10;
switch(rem)
{
case 0:printf("zero ");
break;
case 1:printf("one ");
break;
case 2:printf("two ");
break;
case 3:printf("three ");
break;
case 4:printf("four ");
break;
case 5:printf("five ");
break;
case 6:printf("six ");
break;
case 7:printf("seven ");
break;
case 8:printf("eight ");
break;
case 9:printf("nine ");
break;
}
n=n/10;
}

}
c:\Users\sunil\OneDrive\documents\visual studio 2012...\ConsoleApplication33\assignmenttwo.c 1
#include<stdio.h>
void main()
{
int iNo=0;
int a=0;
int sum;

printf("Enter the value of iNo");


scanf("%d",&iNo);
a=iNo%10;
printf("Last digit is:%d\n",a);
while(iNo>=10)
{
iNo=iNo/10;
}
printf("First Digit is:%d\n",iNo);
sum=a+iNo;
print("%d",sum);
}

}
D:\c language\power.c 1
#include<stdio.h>
void main()
{
int i;
int y;
int x;
printf("Enter value of x");
scanf("%d",&x);
int ans=1;
printf("Enter the value of y");
scanf("%d",&y);
for(i=1;i<=y;i++)
{
ans=ans*x;
}
printf("%d",ans);
}

You might also like