Hello Readers, in this article you will learn different types of C programs important for students of classes 8, 9, 10, 11, 12. These programs include from basic to advance (structure to an array). You may also want to check out the following articles before continuing the programs.
C Programs for Students of 8, 9, 10, 11, 12 - ComputeNepal

 

 

Structure of C Program

// This is the basic structure of C programming
#include <stdio.h>
int main(){ // Block of Statement
 return 0;}

Add two numbers

#include <stdio.h>
int main(){
int a=7, b=5;
printf("The sum is %d",a+b);
return 0;
}

Sum of two numbers

#include <stdio.h>
int main(){
int a,b;
printf("Enter two numbersn");
scanf("%d%d", &a, &b);
printf("Sum = %d", a+b);
return 0;
}

Average of three numbers

#include <stdio.h>
int main(){
float a,b,c;
printf("Enter three numbersn");
scanf("%f%f%f", &a,&b,&c);
printf("The average of three numbers is %0.2f", (a+b+c)/3);
return 0;
}
 

Volume of Cylinder

    #include <stdio.h>
    int main(){
        float r,h;
        printf("Enter radius and heightn");
        scanf("%f%f", &r,&h);
        printf("Volume of cylinder is %0.2f", 3.14*r*r*h);
        return 0;
    }

Area and Circumference of Circle

#include <stdio.h>
int main(){
    float r, pi=3.14;
    printf("Enter radiusn");
    scanf("%f", &r);
    printf("Circumference of Circle is %0.2fn", (2*pi*r));
    printf("Area of circle is %0.2fn", (pi*r*r));
    return 0;
}

Convert Days to respective years, months, and days

#include <stdio.h>
int main(){
    int days, year, month, rem;
    printf("Enter daysn");
    scanf("%d", &days);
    year = days/365;
    rem = days%365;
    month = rem /30;
    days = rem%30;
    printf("%d Years %d Months %d Daysn", year, month, days);
    return 0;
}

Greatest among two numbers

#include <stdio.h>
int main(){
    int a,b;
    printf("Enter two numbersn");
    scanf("%d%d", &a,&b);
    if(a>b){
        printf("%d is greatern", a);
    }
    else{
        printf("%d is greatern", b);
    }
    return 0;
}

Odd or Even

#include<stdio.h>
int main(){
int a;
printf("Enter a numbern");
scanf("%d", &a);
if (a%2 == 0){
printf("The given number is evenn");
}
else{
printf("The given number is oddn");
}
return 0;
}

Positive, Negative, or Zero

#include int main(){ int a; printf(“Enter a numbern”); scanf(“%d”, &a); if(a<0){ printf("The given number is negativen"); } else if(a>0){ printf(“The given number is positiven”); } else{ printf(“The given number is zeron”); } return 0; }

Greatest among three numbers

#include &lt;stdio.h&gt;
int main(){
    int a,b,c;
    printf("Enter three numbersn");
    scanf("%d%d%d", &amp;a,&amp;b,&amp;c);
    if(a&gt;b &amp;&amp; a&gt;c){
        printf("%d is greatern", a);
    }
    else if(b&gt;a &amp;&amp; b&gt;c){
        printf("%d is greatern", b);
    }
    else{
        printf("%d is greatern", c);
    }
    return 0;
}

Classify marks into division

#include &lt;stdio.h&gt;
int main(){
    int marks;
    printf("Enter marksn");
    scanf("%d", &amp;marks);
    if(marks&gt;=80 &amp;&amp; marks&lt;=100){
        printf("Distinctionn");
    }
    else if(marks&gt;=60 &amp;&amp; marks&lt;80){
        printf("First Divisionn");
    }
    else if(marks&gt;=50 &amp;&amp; marks&lt;60){
        printf("Second Divisionn");
    }
    else if(marks&gt;=40 &amp;&amp; marks&lt;50){
        printf("Third Divisionn");
    }
    else{
        printf("Failn");
    }
    return 0;
}

Menu-based program to find the area of circles, rectangles, and triangle

#include &lt;stdio.h&gt;
int main(){
    int ch;
    printf("Press 1 for area of reactanglenPress 2 for area of circlenPress 3 for area of trianglen");
    scanf("%d", &amp;ch);
    int l,br;
    float pi=3.14, r;
    float b,h;
    switch(ch){
        case 1:
            printf("Enter length and breadthn");
            scanf("%d%d", &amp;l, &amp;br);
            printf("Area is %d", (l*br));
            break;
        case 2:
            printf("Enter radiusn");
            scanf("%f", &amp;r);
            printf("Area is %0.2f", (pi*r*r));
            break;
        case 3:
            printf("Enter base and heightn");
            scanf("%f%f", &amp;b,&amp;h);
            printf("Area is %0.2fn", (0.5*b*h));
            break;
        default:
            printf("Wrong Choicen");
            break;
    }
    return 0;
}

Fibonacci Series

#include &lt;stdio.h&gt;
int main(){
    int a=0, b=1,c;
    printf("%dn", a);
    printf("%dn", b);
    for(int i=1; i&lt;9; i++){
        c=a+b;
        printf("%dn", c);
        a=b;
        b=c;
    }
    return 0;
}

Factorial of a given number

#include &lt;stdio.h&gt;
int main(){
    int a, p=1;
    printf("Enter a number\n");
    scanf("%d", &amp;a);
    for(int i=1; i&lt;=a; i++){
        p=p*i;
    }
    printf("Factorial is %d", p);
    return 0;
}

Number palindrome

#include&lt;stdio.h&gt;
int main(){
    int a, b, rem, s=0;
    printf("Enter a number\n");
    scanf("%d", &amp;a);
    b=a;
    while(a != 0){
        rem = a%10;
        s = s*10+rem;
        a = a/10;
    }
    if(b == s){
        printf("Pallindrome");
    }
    else{
        printf("Not pallindrome");
    }
    return 0;
}

Array Example

#include &lt;stdio.h&gt;
int main(){
    int a[10];
    printf("Enter 10 numbersn");
    for(int i=0; i&lt;10; i++){
        scanf("%d", &amp;a[i]);
    }
    printf("You Enteredn");
    for(int i=0; i&lt;10; i++){
        printf("%dt", a[i]);
    }
    return 0;
}

Greatest among ten numbers

#include &lt;stdio.h&gt;
int main(){
    int a[10];
    printf("Enter 10 numbersn");
    for(int i=0; i&lt;10; i++){
        scanf("%d", &amp;a[i]);
    }
    int greatest =a[0];
    for(int i=0; i&lt;10; i++){
        if(a[i] &gt; greatest){
            greatest = a[i];
        }
    }
    printf("Greatest is %d", greatest);
    return 0;
}

Input and Display 3*3 matrix

#include &lt;stdio.h&gt;
int main(){
    int a[3][3];
    printf("Enter elements of matrixn");
    for(int i=0;i&lt;3;i++){
        for(int j=0;j&lt;3;j++){
            scanf("%d", &amp;a[i][j]);
        }
    }
     for(int i=0;i&lt;3;i++){
        for(int j=0;j&lt;3;j++){
            printf("%dt", a[i][j]);
        }
        printf("n");
    }
    return 0;
}

strcat example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "Hello", b[] = "World";
    printf("%s", strcat(a,b));
    return 0;
}

strcmp example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "hi", b[] = "bro";
    if(strcmp(a,b) == 0){
        printf("Equal");
    }
    else{
        printf("Not Equal");
    }
    return 0;
}

strcpy example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "hello", b[10];
    strcpy(b,a);
    printf("%s", b);
    return 0;
}

strlen example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "Hello";
    printf("%d", strlen(a));
    return 0;
}

strlwr example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "HELLO";
    printf("%s", strlwr(a));
    return 0;
}

strrev example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "hello";
    printf("%s", strrev(a));
    return 0;
}

strupr example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main(){
    char a[] = "hello";
    printf("%s", strupr(a));
    return 0;
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *