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

Programs C

This document contains code snippets for 6 different C programs: 1) Fibonacci series, 2) GCD and LCM calculations, 3) palindrome number check, 4) prime number check, 5) factorial calculation, and 6) uppercase/lowercase string conversion. Each code snippet includes header files, function definitions, input/output statements and logic to implement the given programming task in C language.

Uploaded by

vijeshkrishna384
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 views

Programs C

This document contains code snippets for 6 different C programs: 1) Fibonacci series, 2) GCD and LCM calculations, 3) palindrome number check, 4) prime number check, 5) factorial calculation, and 6) uppercase/lowercase string conversion. Each code snippet includes header files, function definitions, input/output statements and logic to implement the given programming task in C language.

Uploaded by

vijeshkrishna384
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/ 4

1) FIBONACCI SERIES

2) #include<stdio.h>
3) void main()
4) {
5) int n,a=0,b=1,c,i;
6) printf("enter the number of terms");
7) scanf("%d",&n);
8) for(i=1;i<=n;i++)
9) {
10) printf("%d",a);
11) c=a+b;
12) a=b;
13) b=c;
14) }
15)}
16)

2) GCD LCM

#include<stdio.h>
void main()
{
int num1, num2, gcd, lcm, remainder, numerator, denominator;
printf("enter two numbers");
scanf("%d%d", num1, num2);
numerator = (num1>num2)?num1:num2;
denominator = (num1<num2)?num1:num2;
remainder = numerator % denominator;
while(remainder!=0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
{
gcd=denominator;
lcm=num1*num2/gcd;
printf("gcd of %d and %d = %d\n, num1 , num2 , gcd");
printf("lcm of %d and %d = %d\n, num1 , num2, lcm");
}
}

}
3) PALINDROME NUMBER

#include<stdio.h>
void main()
{
int m,n,s=0,r;
printf("enter the number");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
n=n/10;
s=s*10+r;
}
if(s==m)
printf(" %d is a palindrome number", m);
else
printf(" %d is not a palindrome number", m);
}

4) PRIME NUMBER

#include<stdio.h>
void main()
{
int n,i,count=0;
printf("enter the value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
printf("it is a prime number");
else
printf("it is not a prime number");
}
5) FACTORIAL

#include<stdio.h>
void main()
{
int n,i,fact=1;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("factorial of %d is %d",n,fact);
}

6)UPPERCASE LOWERCASE

#include<stdio.h>
#include<string.h>
void main()
{
char str[200];
int i=0;
printf("enter a string");
gets(str);
while(str[i]!='\0')
{
if((str[i]>='a')&&(str[i]<='z'))
{
str[i]=str[i]-32;
}
else
if((str[i]>='A')&&(str[i]<='Z'))
{
str[i]=str[i]+32;
}
i++;
}
printf("the converted sting: ");
puts(str);
}
8)ODD EVEN SUM

#include<stdio.h>
void main()
{
int num;
printf("enter the number");
scanf("%d",&num);
if(num%2==0)
printf("%d is even number",num);
else
printf("%d is a odd number",num);
}

You might also like