









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In these document some basic C programming language programs are written.
Typology: Study notes
1 / 15
This page cannot be seen from the preview
Don't miss anything!










/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(); }
#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(); }
#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); }
#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(); }
#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(); }
#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); }
#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(); }
#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(); }
#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(); }
#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); } }
#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);
/*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(); }
#include<stdio.h> #include<conio.h> int fact(int x); void main() { int num,f;