C PROGRAMS FOR BEGINNERS, Study notes of C programming

In these document some basic C programming language programs are written.

Typology: Study notes

2020/2021

Uploaded on 01/06/2022

Vikram_jangid
Vikram_jangid 🇮🇳

2 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
List Of Programs by Vikram
1. TO CALCULATE SUM AND PERCENTAGE MARKS OBTAINED BY A
STUDENT IN FIVE SUBJECTS.
/*CALCULATE SUM AND PERCENTAGE*/
#include <stdio.h>
#include <conio.h>
void main ()
{
int math , ppa , fund , pom , busi , sum ;
float perct ;
printf ( " \n Maths marks : " );
scanf ( " %d " , & math );
printf ( " \n PPA marks : " );
scanf ( " %d " , & ppa );
printf ( " \n Fundamental marks : " );
scanf ( " %d " , & fund );
printf ( " \n POM marks:" );
scanf ( " %d " , & pom );
printf ( " \n Business marks : " );
scanf ( " %d " , & busi );
sum = math + ppa + fund + pom + busi ;
perct = ( sum * 100 / 500.0 );
printf ( " \n Total marks obtain: %d " , sum );
printf ( " \n Percentage: %f \n " , perct );
getch ();
}
2. TO CALCULATE SIMPLE INTEREST AND COMPOUND INTEREST .
/*CALCULATE SIMPLE INTEREST AND COMPOUND INTEREST*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ()
{
float principle , time , rate , SI , CI ;
printf ( " \n Principle amount : " );
scanf ( " %f " , & principle );
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download C PROGRAMS FOR BEGINNERS and more Study notes C programming in PDF only on Docsity!

List Of Programs by Vikram

1. TO CALCULATE SUM AND PERCENTAGE MARKS OBTAINED BY A

STUDENT IN FIVE SUBJECTS.

/CALCULATE SUM AND PERCENTAGE/

#include <stdio.h>

#include <conio.h>

void main()

int math, ppa, fund, pom, busi, sum;

float perct;

printf("\nMaths marks : ");

scanf("%d", &math);

printf("\nPPA marks : ");

scanf("%d", &ppa);

printf("\nFundamental marks : ");

scanf("%d", &fund);

printf("\nPOM marks:");

scanf("%d", &pom);

printf("\nBusiness marks : ");

scanf("%d", &busi);

sum = math + ppa + fund + pom + busi;

perct = (sum*100 / 500.0);

printf("\nTotal marks obtain:%d", sum);

printf("\nPercentage: %f\n", perct);

getch();

2. TO CALCULATE SIMPLE INTEREST AND COMPOUND INTEREST.

/CALCULATE SIMPLE INTEREST AND COMPOUND INTEREST/

#include <stdio.h>

#include <conio.h>

#include <math.h>

void main()

float principle, time, rate, SI, CI;

printf("\nPrinciple amount : ");

scanf("%f", &principle);

printf("\nTime : ");

scanf("%f", &time);

printf("\nRate : ");

scanf("%f", &rate);

SI = principle * time * rate / 100;

CI = principle * pow((1 + rate / 100), time);

printf("\nSimple interest :%f", SI);

printf("\nCompound interest : %f\n", CI);

getch();

3. To calculate the gross salary of an employee. The basic

salary is entered through the keyboard.

HRA=60% of BS

DA= 10% of BS

GS=BS+HRA+DA

/To calculate the gross salary of an employee. The basic salary is entered through the keyboard. HRA=60% of BS DA= 10% of BS GS=BS+HRA+DA/ #include<stdio.h> #include<conio.h> void main() { float bs, gs, da, hra;

printf("Enter basic salary\n"); scanf("%f", &bs);

if( bs < 5000 ) { hra = bs * 60 / 100; da = bs * 10 / 100; } else { hra = 600; da = bs * 95 / 100; } gs = bs + hra + da;

printf("Gross Salary is Rs %f\n", gs);

getch(); }

int a, b;

printf("\nEnter value of a : ");

scanf("%d", &a);

printf("\nEnter value of b : ");

scanf("%d",&b);

a=a+b;

b=a-b;

a=a-b;

printf("\nAfter swap value of a = %d and b = %d.",a,b);

getch();

7. PROGRAM TO CONVERT CENTIGRADE TO FAHRENHEIT.

/* PROGRAM TO CONVERT CENTIGRADE TO FAHRENHEIT.*/

#include <stdio.h>

#include <conio.h>

void main()

int centigrade,fahrenheit;

printf("\nEnter temperature in centigrade : ");

scanf("%d", centigrade);

fahrenheit=centigrade*9/5+32;

printf("\nTemperature in fahrenheit : %d ",fahrenheit);

getch();

8. TO CHECK IF THE ENTERED CHARACTER IS LOWERCASE OR NOT.

/*TO CHECK IF THE ENTERED CHARACTER IS LOWERCASE OR NOT.

#include <stdio.h>

#include <conio.h>

void main()

char ch;

printf("\nEnter a character : ");

scanf("%c", &ch);

if (ch >= 'A' && ch <= 'Z')

printf("\n'%c' is an UpperCase character.",ch);

else if (ch >= 'a' && ch <= 'z')

printf("\n'%c' is an LowerCase character.",ch);

else

printf("\n'%c' is not an alphabetic character.\n",ch);

getch();

9. TO PRINT THE GREATEST AMONG THREE NUMBERS USING LOGICAL

OPERATORS.

/*TO PRINT THE GREATEST AMONG THREE NUMBERS USING LOGICAL

OPERATORS.*/

#include <stdio.h>

#include <conio.h>

void main() {

int n1, n2, n3;

printf("Enter three different numbers: ");

scanf("%d %d %d", &n1, &n2, &n3);

if (n1 >= n2 && n1 >= n3)

printf("%d is the largest number.", n1);

if (n2 >= n1 && n2 >= n3)

printf("%d is the largest number.", n2);

if (n3 >= n1 && n3 >= n2)

printf("%d is the largest number.", n3);

getch();

10. TO FIND WHETHER THE NUMBER ENTERED IS EVEN OR ODD.

/* TO FIND WHETHER THE NUMBER ENTERED IS EVEN OR ODD.*/

#include <stdio.h>

#include <conio.h>

void main()

int number;

printf("Enter number: ");

scanf("%d", &number);

if (number%2==0)

printf("Number is Even.");

else

printf("Number is Odd.");

getch();

11. TO FIND WHETHER THE ENTERED YEAR IS A LEAP YEAR OR NOT.

/* TO FIND WHETHER THE YEAR IS LEAP OR NOT.*/

#include <stdio.h> #include <conio.h> void main() { int year; printf("Enter Year: ");

int num, i, sum = 0; printf(" Enter a positive number: "); scanf("%d", &num); for (i = 0; i <= num; i++) { sum = sum + i; }

printf("\n Sum of the first %d number is: %d\n", num, sum); getch(); }

14. TO FIND THE FACTORIAL OF A NUMBER.

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

15. TO PRINT TABLES OF ANY NUMBER.

#include <stdio.h> #include <conio.h> void main() { int num, i; printf (" Enter a number to generate the table in C: "); scanf (" %d", &num); printf ("\n Table of %d", num); for ( i = 1; i <= 10; i++) { printf ("\n %d * %d = %d", num, i, (num*i)); } getch(); }

16. TO CONVERT BINARY NUMBERS TO DECIMAL.

/TO CONVERT BINARY NUMBERS TO DECIMAL./

#include <stdio.h> #include <conio.h> void main()

int num, binary_num, decimal_num = 0, base = 1, rem; printf (" Enter a binary number with the combination of 0s and 1s \n"); scanf ("%d", &num);

binary_num = num; while ( num > 0) { rem = num % 10; decimal_num = decimal_num + rem * base; num = num / 10; base = base * 2; }

printf ( " The binary number is %d \t", binary_num); printf (" \n The decimal number is %d \t", decimal_num); getch(); }

17. PROGRAM TO FIND THE SUM OF EVEN AND ODD NUMBERS FROM 1 TO

//PROGRAM TO FIND THE SUM OF EVEN AND ODD NUMBERS FROM 1 TO 100.

#include<stdio.h> #include<conio.h> void main() { int ev_sum=0,od_sum=0,i; for (i = 1; i<=100; i++) { if(i%2==0) { ev_sum=ev_sum+i; } else od_sum=od_sum+i; } printf("Sum of even number from 1 to 100: %d\n",ev_sum); printf("Sum of odd number from 1 to 100: %d\n",od_sum); }

18. TO GENERATE FIBONACCI SERIES (0,1,1,2,3,5,8,……)

#include <stdio.h> #include <conio.h> void main() { int n, a = 0, b = 1, c, i; printf("Enter any term: "); scanf("%d", &n);

r = number % 10; sum = sum + r; number = number / 10; } printf("Sum of digit of %d is %d.\n",n,sum); getch(); }

21. TO CHECK IF THE ENTERED NUMBER IS PALINDROME OR NOT.

//TO CHECK IF THE ENTERED NUMBER IS PALINDROME OR NOT.

#include <stdio.h> #include <conio.h> void main() { int number, r, s = 0, p; printf("Enter any number: "); scanf("%d", &number); p = number; while (number > 0) { r = number % 10; s = s * 10 + r; number = number / 10; } if (p == s) { printf("Number is Palindrome.\n"); } else printf("Number is not Palindrome.\n"); getch(); }

22. TO REVERSE THE GIVEN NUMBER.

/TO REVERSE THE GIVEN NUMBER./

#include <stdio.h> #include <conio.h> void main() { int number,r,s=0; printf("Enter any number: "); scanf("%d", &number); while(number>0) { r=number%10; s=s*10+r; number=number/10;

printf("Reverse is %d\n",s);

getch(); }

23.TO PROGRAM USING BREAK STATEMENTS.

//TO PROGRAM USING BREAK STATEMENTS.

#include<stdio.h> #include<conio.h> void main() { int i; for(i=1;i<=6;i++) { if(i==3) { printf("HELLO\n"); break; } else if(i==4) { printf("WORLD\n"); } else printf("%d\n",i); } }

24.TO PROGRAM USING A CONTINUE STATEMENT.

// TO PROGRAM USING A CONTINUE STATEMENT.

#include<stdio.h> #include<conio.h> void main() { int i; for(i=1;i<=6;i++) { if(i==3) { printf("HELLO\n"); continue; } else if(i==4) { printf("WORLD\n"); } else printf("%d\n",i);

27.TO PRINT PATTERNS:

/*Pattern: 12345 1234 123 12 1 */

#include <stdio.h> #include <conio.h> void main() { int i, j; for (i = 5; i >= 1; i--) { for (j = 1; j <= i; j++) { printf("%d",j); } printf("\n"); } getch(); }

/*Pattern: 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 */ #include <stdio.h> #include <conio.h> void main() {

int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { if((i+j)%2==0) printf("1"); else printf("0"); } printf("\n"); } getch(); }

#include <stdio.h> #include <conio.h> void main() { int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) //(j = 5; j >= i; j--) { printf("@ "); } printf("\n"); } getch(); }

30.TO CALCULATE FACTORIAL USING A RECURSIVE FUNCTION.

//TO CALCULATE FACTORIAL USING A RECURSIVE FUNCTION.

#include<stdio.h> #include<conio.h> int fact(int x); void main() { int num,f;