Ad Code

7 Must-Know C Programs for Beginners: Fibonacci, Prime Numbers, Palindrome, and More.

Seven C Language Programs 

 ( Must Know! )

Welcome to CodingFizz,


This tutorial is a must-read for beginners and freshers who are interested in learning the C programming language. The tutorial includes important C programs that every beginner should know. These programs are Fibonacci Series, Prime Number, Palindrome, Reverse a Number, Armstrong Number, Factorial of a number, and Sum of Digits.

C is a popular general-purpose structured programming language that is widely used today. It is often referred to as a "system programming language" because it is useful for writing operating systems. Additionally, C is powerful in writing major numerical, text, and data processing applications. Due to its versatility, C is often referred to as a middle-level language.

The tutorial includes step-by-step instructions for each program, along with code examples and explanations. The Fibonacci Series program generates the Fibonacci series up to a specified number, while the Prime Number program checks if a given number is a prime number or not. The Palindrome program checks if a given word or number is a palindrome, while the Reverse a Number program reverses a given number.

Furthermore, the tutorial also covers the Armstrong Number program, which checks if a given number is an Armstrong number or not. The Factorial of a number program calculates the factorial of a given number, and the Sum of Digits program calculates the sum of digits in a given number.

By following this tutorial, beginners can learn the fundamental concepts of C programming language and develop a strong foundation in programming.

Programs:

#1 Fibonacci Series

 #include <stdio.h>
 int main()
 {   
    int n0=0,n1=1, n2,i,num;
    printf("Enter the Number: ");
    scanf("%d",&num);
    printf("\n%d %d",n0,n1);
    for(i=2;i<num;i++){
        n2=n0+n1;
        printf(" %d",n2);
        n0=n1;
        n1=n2;
    }
    return 0;
 }
Output:

Enter the Number: 12
0 1 1 2 3 5 8 13 21 34 55 89

#2 Prime Number Or Not

 #include<stdio.h>
 int main() {
    int n,i=2;
    printf("Enter the number: \n");
    scanf("%d",&n);
    while(i<n){
        if(n%i==0){
            break;
        }
        else{
            i=i+1;
        }
    }
    if(i==n){
        printf("%d is a prime number",n); 
    }
    else{
        printf("%d is not a prime number",n); 
    }
    return 0;
 }

Output:

Enter the number: 3

3 is a prime number

#3 Palindrome Or Not

 #include <stdio.h>    
 #include <string.h>  

 void main()  
 { 

   int num, digit, reverse=0;
   printf("Enter Digits: ");
   scanf("%d",&num);
    int temp=num;

    while(num>0){
        digit=num%10;
        reverse=(reverse*10)+digit;
        num=num/10;
    }

    if(temp==reverse)
    printf("%d is a palindrome",num);
    else
    printf("%d is not a palindrome",num);
 }  

Output:

Enter Digit: 232

232 is palindrome

Output:

Enter Digit: 234

234 is not a palindrome

#4 Reverse a Number

#include <stdio.h>    
 #include <string.h>  
 void main()  
 {  
   int num, digit, reverse=0;
   printf("Enter Digits: ");
   scanf("%d",&num);

    while(num>0){
        digit=num%10;
        reverse=(reverse*10)+digit;
        num=num/10;
    }

    printf ("Reversed of given Digits: %d ",  reverse);
 } 

Output:

Enter Digits: 23425
Reversed of given Digits: 52432

#5 Armstrong Number Or Not

 #include <stdio.h>    
 #include <string.h>  
 void main()  
 { 
   int num, rem, sum=0;
   printf("Enter Digits: ");
   scanf("%d",&num);
    int temp=num;

    while(num>0){
        rem=num%10;
        sum=sum+(rem*rem*rem);
        num=num/10;
    }

    if(temp==sum)
    printf("Armstrong Number");
    else
    printf("Not Armstrong Number");
 }


Output:

Enter Digits: 123
Not Armstrong Number

Or

Enter Digits: 153
Armstrong Number

#6 Factorial Of A Number

 #include <stdio.h>    
 #include <string.h>  
 void main()  
 { 
  int i, fact=1, num;
  printf("Enter a number: ");
  scanf("%d",&num); 
  for(i=1; i<=num; i++){
      fact=fact*i;
  }
  printf("Factorial of %d is %d",num,fact);
 }  

Output:

Enter a number: 5
Factorial of 5 is 120

#7 Sum Of A Digit

 #include <stdio.h>
 #include <conio.h>
 int main()
 {
    int digit,rem,sum=0;
    printf("Enter a digit: ");
    scanf("%d",&digit);
    while(digit>0){
        rem=digit%10;
        sum=sum+rem;
        digit=digit/10;
    }
    printf("Sum of digit: %d",sum);
    return 0;
 }


Output:

Enter a digit: 7865434

Sum of digit: 37

Post a Comment

1 Comments

Ad Code