0% found this document useful (0 votes)
4 views16 pages

FPC All Programs With Code

The document provides practical programming examples in C, covering fundamental concepts such as input/output, control structures, and data types. It includes code snippets for various programs, including checking even/odd numbers, finding the largest of three numbers, calculating factorials, and working with arrays and files. Each example is accompanied by a brief description of its functionality.
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)
4 views16 pages

FPC All Programs With Code

The document provides practical programming examples in C, covering fundamental concepts such as input/output, control structures, and data types. It includes code snippets for various programs, including checking even/odd numbers, finding the largest of three numbers, calculating factorials, and working with arrays and files. Each example is accompanied by a brief description of its functionality.
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

FPC (Fundamentals of Programming in C) – ALL

Practical Programs with Full Code

1. Hello World
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
2. Even or Odd
#include <stdio.h>
int main() {
int n;
scanf("%d",&n);
if(n%2==0) printf("Even");
else printf("Odd");
return 0;
}
3. Largest of 3 Numbers
#include <stdio.h>
int main() {
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c) printf("A is largest");
else if(b>c) printf("B is largest");
else printf("C is largest");
return 0;
}
4. Prime Number
#include <stdio.h>
int main() {
int n,i,flag=0;
scanf("%d",&n);
for(i=2;i<n;i++)
if(n%i==0){ flag=1; break; }
if(flag==0) printf("Prime");
else printf("Not Prime");
return 0;
}
5. Factorial
#include <stdio.h>
int main() {
int n,i,f=1;
scanf("%d",&n);
for(i=1;i<=n;i++) f=f*i;
printf("Factorial = %d",f);
return 0;
}
6. Fibonacci Series
#include <stdio.h>
int main() {
int n,a=0,b=1,c,i;
scanf("%d",&n);
printf("%d %d ",a,b);
for(i=2;i<n;i++){
c=a+b;
printf("%d ",c);
a=b; b=c;
}
return 0;
}
7. Reverse a Number
#include <stdio.h>
int main() {
int n,rev=0;
scanf("%d",&n);
while(n!=0){
rev=rev*10+n%10;
n/=10;
}
printf("Reverse = %d",rev);
return 0;
}
8. Palindrome Number
#include <stdio.h>
int main() {
int n,temp,rev=0;
scanf("%d",&n);
temp=n;
while(n!=0){
rev=rev*10+n%10;
n/=10;
}
if(temp==rev) printf("Palindrome");
else printf("Not Palindrome");
return 0;
}
9. Armstrong Number
#include <stdio.h>
int main() {
int n,temp,r,sum=0;
scanf("%d",&n);
temp=n;
while(n!=0){
r=n%10;
sum=sum+r*r*r;
n/=10;
}
if(sum==temp) printf("Armstrong");
else printf("Not Armstrong");
return 0;
}
10. Sum of Array
#include <stdio.h>
int main() {
int a[100],n,i,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<n;i++) sum+=a[i];
printf("Sum = %d",sum);
return 0;
}
11. Bubble Sort
#include <stdio.h>
int main() {
int a[100],n,i,j,temp;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<n;i++) printf("%d ",a[i]);
return 0;
}
12. String Palindrome
#include <stdio.h>
#include <string.h>
int main() {
char s[50];
int i,len,flag=0;
scanf("%s",s);
len=strlen(s);
for(i=0;i<len/2;i++)
if(s[i]!=s[len-i-1]){ flag=1; break; }
if(flag==0) printf("Palindrome");
else printf("Not Palindrome");
return 0;
}
13. Pointer Basic
#include <stdio.h>
int main() {
int a=10;
int *p=&a;
printf("Value = %d",*p);
return 0;
}
14. Structure Program
#include <stdio.h>
struct student {
int roll;
char name[20];
};
int main() {
struct student s;
scanf("%d %s",&[Link],[Link]);
printf("%d %s",[Link],[Link]);
return 0;
}
15. File Write
#include <stdio.h>
int main() {
FILE *fp;
fp=fopen("[Link]","w");
fprintf(fp,"Hello File");
fclose(fp);
return 0;
}
16. File Read
#include <stdio.h>
int main() {
FILE *fp;
char ch;
fp=fopen("[Link]","r");
while((ch=fgetc(fp))!=EOF)
printf("%c",ch);
fclose(fp);
return 0;
}

You might also like