10+ C Programs for Beginners: Learn Coding Basics Easily

Look at a list of 10+ beginner-friendly C programs designed to help you take the fundamentals of coding.

Mar 11, 2024 - 09:11
Mar 11, 2024 - 09:14
 0

This C language program collection has more than 20 programs, covering beginner level programs like Hello World, Sum of Two numbers, etc. to complex programs like, Prime Numbers, and pattern printing programs.

All the programs have working code along with their output. We suggest you to learn the basics of C language from our C tutorial, before getting started with the C programs.

Write a program to ask ten numbers from the user and display them

#include
int main(){
	int numbers[10];
	
	for(int i = 0; i < 10; i++){
		printf("Enter a number: ");
		scanf("%d", &numbers[i]);
	}
	
	for(int i = 0; i < 10; i++){
		printf("\n %d ", numbers[i]);
	}
	

	return 0;
}

Write a program to read  'n' numbers and to find sum and average.

#include

//Write a program to read'n' numbers and to find sum and average

int main(){
	
 float a[100], sum=0, avg;
 int i, n;
 
 printf("Enter n: ");
 scanf("%d", &n);
 
 /* Reading array */
 printf("Enter numbers:\n");
 for(i=0; i< n; i++)
 {
  printf("a[%d] = ", i);
  scanf("%f", &a[i]);
 }
 
 /* Finding sum */
 for(i=0; i< n; i++)
 {
  sum = sum + a[i];
 }
 
 /* Calculating average */
 avg = sum/n;
 
 /* Displaying Result */
 printf("Sum is %f\n", sum);
 printf("Average is %f", avg);
 
 return 0;
}

Write a c program to find the greatest number among four numbers

#include<stdio.h>

//Write a program to find the greatest number among four numbers

int main()
{
	int a,b,c,d;
	printf("input four different numbers=");
	scanf("%d %d %d %d",&a,&b,&c,&d);
if(a>b&&a>c&&a>d)
{
printf("%d is the greatest number",a);
}
else if(b>c&&b>d)
{
printf("%d is the greatest number",b);
}
else if(c>d)
{
printf("%d is the greatest number",c);
}
else
{
printf("%d is the greatest number",d);
}
}

write a c program to find the average of three number

#include <stdio.h>

int main() {
    float num1, num2, num3, average;

    // Ask the user to enter three numbers
    printf("Enter three numbers: ");
    scanf("%f %f %f", &num1, &num2, &num3);

    // Calculate the average
    average = (num1 + num2 + num3) / 3;

    // Display the average
    printf("The average of %.2f, %.2f, and %.2f is: %.2f\n", num1, num2, num3, average);

    return 0;
}

Write a program to store 10 numbers in a array and print out the greatest number among them

#include<stdio.h>

//Write a program to store 10 numbers in a array and print out the greatest number among them
int main(){
	
	 int a[10];
    int i;
    int greatest;
    printf("Enter ten values:");
    //Store 10 numbers in an array
    for (i = 0; i < 10; i++) {
        scanf("%d", &a[i]);
    }
    //Assume that a[0] is greatest
    greatest = a[0];
    for (i = 0; i < 10; i++) {
        if (a[i] > greatest) 
		{
        greatest = a[i];
    	}
    }
    printf("Greatest of ten numbers is %d", greatest);
    return 0;
	
	return 0;
}

Write a program to input n numbers and find out largest and smallest among them

#include<stdio.h>

//Write a program to input n numbers and find out largest and smallest among them

int main()
{
    int i, n, lar,sm, elem;
    printf ("Enter total number of elements n: ");
    scanf ("%d", &elem);
    printf ("Enter first number n: ");
    scanf ("%d", &n);
    lar = n;
    sm=n;
    for (i=1; i<= elem -1 ; i++)
    {
        printf ("Enter another number n: ");
        scanf ("%d",&n);
        if (n>lar)
        lar=n;
        if (n<sm)
        sm=n;
    }
    printf ("\n The largest number is %d", lar);
    printf ("\n The smallest number is %d", sm);
    return 0;
}

Write a program to search whether a number entered by the user is following the data set or not. Data set are  12,45,56,67,78,560,47,78

#include<stdio.h>
//Write a program to search whether a number entered by the user is following the data set or not. Data set are  12,45,56,67,78,560,47,78
int main(){
	
	 int dataSet[] = {12, 45, 56, 67, 78, 560, 47, 78};
    int userNumber, i, isFound;

    printf("Enter a number: ");
    scanf("%d", &userNumber);

    isFound = 0;
    for (i = 0; i < 8; i++) {
        if (dataSet[i] == userNumber) {
            isFound = 1;
            break;
        }
	}
	
	if (isFound) {
        printf("The number is in the data set.\n");
    } else {
        printf("The number is not in the data set.\n");
    }

    return 0;
}

Write a program to read salaries of 200 employees and count the number of employees getting salary of 5000 to 10000

#include<stdio.h>

//Write a program to read salaries of 200 employees and count the number of employees getting salary of 5000 to 10000
int main(){
	
    int salary[200], i, count = 0;

    // Read salaries of up to 200 employees
    for (i = 0; i < 200; i++) {
        printf("Input salary of employee %d: ", i + 1);
        scanf("%d", &salary[i]);

        // Count the number of employees getting a salary between 5000 and 10000
        if (salary[i] > 5000 && salary[i] < 10000) {
            count++;
        }
    }

    printf("Number of employees getting salary between 5000 and 10000: %d\n", count);

    return 0;
	
}

Write a program to read the age of 40 students and count the numbers of students aged between 15 and 22

#include<stdio.h>

//Write a program to read the age of 40 students and count the numbers of students aged between 15 and 22

int main() {
    int age[40], i, count = 0;

    // Read ages of 40 students
    for (i = 0; i < 40; i++) {
        printf("Input age of student %d: ", i + 1);
        scanf("%d", &age[i]);

        // Count the number of students aged between 15 and 22
        if (age[i] >= 15 && age[i] <= 22) {
            count++;
        }
    }

    printf("Number of students aged between 15 and 22: %d\n", count);

    return 0;
}

Write a program to read the age of 100 persons and count the number of persons in the age group between 50 and 60.

#include <stdio.h>

//Write a program to read the age of 100 persons and count the number of persons in the age group between 50 and 60.

int main() {
    int age[100], i, count = 0;

    // Read ages of 100 persons
    for (i = 0; i < 100; i++) {
        printf("Enter the age of person %d: ", i + 1);
        scanf("%d", &age[i]);

        // Count the number of persons aged between 50 and 60
        if (age[i] >= 50 && age[i] <= 60) {
            count++;
        }
    }

    printf("Number of persons in the age group 50 to 60 is %d\n", count);

    return 0;
}

Write a program to store the marks obtained 'n' students and count the number of students who obtained marks greater than 70.Also count the number of students who are failed

#include <stdio.h>

//Write a program to store the marks obtained 'n' students and count the number of students who obtained marks greater than 70.Also count the number of students who are failed

int main() {
    int marks[100], i, n, count_gt70 = 0, count_failed = 0;

    printf("Enter the number of students: ");
    scanf("%d", &n);

    // Read marks of n students
    for (i = 0; i < n; i++) {
        printf("Enter the marks of student %d: ", i + 1);
        scanf("%d", &marks[i]);

        // Count the number of students who obtained marks greater than 70
        if (marks[i] > 70) {
            count_gt70++;
        }

        // Count the number of students who are failed
        if (marks[i] <= 35) {
            count_failed++;
        }
    }

    printf("Number of students who obtained marks greater than 70 is %d\n", count_gt70);
    printf("Number of students who are failed is %d\n", count_failed);

    return 0;
}

Learn C From Programiz

C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on. C programming is an excellent language to learn to program for beginners.

Programiz C tutorials will guide you to learn C programming one step at a time.

Don't know how to learn C Programming, the right way? Enroll in our Interactive C Course for FREE.

Linkupnepal