Bachelor of Technology in Information Technology



Download 0,65 Mb.
bet8/14
Sana20.03.2022
Hajmi0,65 Mb.
#502184
1   ...   4   5   6   7   8   9   10   11   ...   14
Bog'liq
PSP Lab Manual

ALGORITHM:


Step 1: Start.
Step 2: declare n, n1, and rev = 0, rem Step 3: print enter an integer.
Step 4: read n.
Step 5: n1 = n.
Step 6: while (n > 0) { rem = n % 10
rev = rev * 10 + rem n = n / 10
Step 7: if (n1 == rev)
Print number is palindrome.

Step 8: else

Step 9: Stop.


Print number is not palindrome.





SOURCE CODE:


#include



int main()
{
int n, n1, rev = 0, rem;

printf("Enter any number: "); scanf("%d", &n);


n1 = n;

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


rev = rev * 10 + rem; n = n / 10;
}

if (n1 == rev){


printf("%d is a palindrome.", rev);
}
else{
printf("%d is not a palindrome.", rev);
}
return 0;
}
  1. C program to find the GCD/LCM of two given integers ALGORITHM:


Step 1: Start.
Step 2: Step 3: print enter two integers. Step 4: read n1, n2.
Step 5: x=n1
y=n2
Step 6: while ( n1≠n2) Step 7: if(n1>n2)
n1 ← n1-n2 n2←n2-n1
Step 8: gcd← n1
Step 9: lcm ← (x*y)/gcd
Step 10: Print gcd is Greatest common divisor. Step 11: print lcm is Least common multiplier. Step 12: Stop.

SOURCE CODE:


#include


int main()
{

int n1,n2,x,y,gcd,lcm; printf("Enter two numbers:\n"); scanf("%d%d",&n1,&n2);


x=n1; y=n2;
while(n1!=n2)
{
if(n1>n2)
{
n1=n1-n2;
}
else
{
n2=n2-n1;
}
}
gcd=n1; lcm=(x*y)/gcd;
printf("Greatest common divisor=%d\n",gcd); printf("Least commom multiple=%d",lcm);
return 0;
}
------------------------------*-----------OUTPUT----------------*------------------------



  1. Download 0,65 Mb.

    Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   ...   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish