C Code Archive

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C Code Archive as PDF for free.

More details

  • Words: 1,825
  • Pages: 20
Task-1: A program to generate triangle of ‘*’. #include<stdio.h> #include void main() { clrscr(); printf("*****\n"); printf("****\n"); printf("***\n"); printf("**\n"); printf("*\n"); getch(); } Task-2: A program to generate numeric triangle. #include<stdio.h> #include void main() { clrscr(); printf("1\n"); printf("1 2\n"); printf("1 2 3\n"); printf("1 2 3 4\n"); printf("1 2 3 4 5\n"); getch(); } Task-3: A program to display own name using variables. #include<stdio.h> #include void main() { clrscr(); char m,u,r,t,a,z,c; m='M'; u='u'; r='r'; t='t'; a='a'; z='z'; c='a'; printf("My name is %c%c%c%c%c%c%c",m,u,r,t,a,z,c);

getch(); } Task-4: A program to give the sum of two numbers using variables. #include<stdio.h> #include void main() { clrscr(); int a,b,c; a=10; b=35; c=a+b; printf("The sum of %d and %d is %d.",a,b,c); getch(); } Task-5: A program to find out the sum of two integers as a floating point number. #include<stdio.h> #include void main() { clrscr(); int a,b; float c; a=35; b=26; c=a+b; printf("The sum of %d and %d is %f.",a,b,c); getch(); } Task-6: A program to convert Celsius temperature into Fahrenheit temperature taking values in the runtime environment. #include<stdio.h> #include void main() { clrscr(); float c,f; printf("Enter the Celsius temperature: "); scanf("%f",&c); f=((9*c)/5)+32;

printf("Temperature in Fahrenheit is %.3f",f); getch(); } Task-7: A program to find out the area of a circle. #include<stdio.h> #include void main() { clrscr(); float r,p,a; printf("Enter the radius of the circle: "); scanf("%f",&r); p=3.14159; a=p*r*r; printf("The area of the circle is: %.3f",a); getch(); } Task-8: A program to convert a floating point number into a integer value. #include<stdio.h> #include void main() { clrscr(); float a; int b; printf("Enter the floating value: "); scanf("%f",&a); b=a; printf("The integer value is: %d.",b); getch(); } Task-9: A program to convert dollars into cents. #include<stdio.h> #include void main() { clrscr(); float d,c; printf("How many dollars to convert?: "); scanf("%f",&d);

c=d*100; printf("You can get %.2f cents from %.2f dollars.",c,d); getch(); } Task-10: A program to calculate the value of X where X = Y4 + 3Y3 + 5Y2 + 3Y + 2. #include<stdio.h> #include #include<math.h> void main() { clrscr(); int x,y; printf("Enter the value of Y: "); scanf("%d",&y); x=pow(y,4)+3*pow(y,3)+5*pow(y,2)+3*y+2; printf("The value of X is %d.",x); getch(); } Task-11: A program to calculate distance using the equation d = ut + 1/2 at2. #include<stdio.h> #include #include<math.h> void main() { clrscr(); float d,u,t,a; printf("Enter the initial velocity: "); scanf("%f",&u); printf("\a"); printf("Enter the time: "); scanf("%f",&t); printf("\a"); printf("Enter the accelaration: "); scanf("%f",&a); printf("\a"); d=u*t+((a*pow(t,2))/2); printf("The distance is %.3f",d); getch(); }

Task-12: A program to calculate the frequency using the equation f = #include<stdio.h> #include #include<math.h> void main() { clrscr(); float f,l,c,r; printf("What is the value of Inductance?: "); scanf("%f",&l); printf("\a"); printf("What is the value of Resistance?: "); scanf("%f",&r); printf("\a"); printf("What is the value of Capacitance?: "); scanf("%f",&c); printf("\a"); f=sqrt((1/(l*c))-(pow(r,2)/(4*pow(c,2)))); printf("The frequency is %.3f Hz.",f); getch(); } Task-13: A program that displays message based on condition. #include<stdio.h> #include void main() { clrscr(); char d; printf("Press a key to see what happen:(B/C) "); scanf("%c",&d); if (d=='b') { printf("Bird flies when cat is sighted."); } else { printf("Cat wants to grab the bird."); } getch(); }

1 r2 − lc 4c 2

Task-14: A program that displays a number between 0 and 10 in words on the corresponding key press. #include<stdio.h> #include void main() { clrscr(); int a; printf("Enter a number between 0 and 10: "); scanf("%d",&a); if (a==0) { printf("0 -> Zero."); } else if (a==1) { printf("1 -> One."); } else if (a==2) { printf("2 -> Two."); } else if (a==3) { printf("3 -> Three."); } else if (a==4) { printf("4 -> Four."); } else if (a==5) { printf("5 -> Five."); } else if (a==6) { printf("6 -> Six."); } else if (a==7) { printf("7 -> Seven."); } else if (a==8) { printf("8 -> Eight.");

} else if (a==9) { printf("9 -> Nine."); } else if (a==10) { printf("10 -> Ten."); } else { printf("Value out of Range."); } getch(); } Task-15: A program that tells whether a given number odd or even. #include<stdio.h> #include void main() { clrscr(); int a,b; printf("Enter a number: "); scanf("%d",&a); b=a%2; if (b==0) { printf("The number is Even."); } else { printf("The number is Odd."); } getch(); } Task-16: A program to find out the largest and the smallest number among three given values. #include<stdio.h> #include void main() { clrscr();

int a,b,c; printf("Enter the first number: "); scanf("%d",&a); printf("Enter the second number: "); scanf("%d",&b); printf("Enter the third number: "); scanf("%d",&c); if (a>b) { if (a>c) { printf("%d is the largest number.\n",a); if (b>c) { printf("%d is the smallest number.",c); } else { printf("%d is the smallest number.",b); } } else { printf("%d is the largest number.\n",c); if (a>b) { printf("%d is the smallest number.",b); } else { printf("%d is the smallest number.",a); } } } else if (b>c) { printf("%d is the largest number.\n",b); if (a>c) { printf("%d is the smallest number.",c); } else { printf("%d is the smallest number.",a); } }

else { printf("%d is the largest number.\n",c); if (a>b) { printf("%d is the smallest number.",b); } else { printf("%d is the smallest number.",a); } } getch(); } Task-17: A program that takes the numbers of different subjects and gives the total and the division of pass depending on the total. #include<stdio.h> #include void main() { clrscr(); int m1,m2,p1,p2,c1,c2,opt,b1,b2,t; printf("Marks in Math:\n\tPart-1\t"); scanf("%d",&m1); printf("\tPart-2\t"); scanf("%d",&m2); printf("Marks in Math\t%d out of\t200\n",m1+m2); printf("Marks in Physics:\n\tPart-1\t"); scanf("%d",&p1); printf("\tPart-2\t"); scanf("%d",&p2); printf("Marks in Physics\t%d out of\t200\n",p1+p2); printf("Marks in Chemistry:\n\tPart-1\t"); scanf("%d",&c1); printf("\tPart-2\t"); scanf("%d",&c2); printf("Marks in Chemistry\t%d out of\t200\n",c1+c2); printf("Marks in Biology:\n\tPart-1\t"); scanf("%d",&b1); printf("\tPart-2\t"); scanf("%d",&b2); opt=b1+b2; if (opt>80) {

t=m1+m2+p1+p2+c1+c2+(opt-80); } else { t=m1+m2+p1+p2+c1+c2; } printf("Marks in Biology\t%d out of\t120\n",opt-80); printf("Marks total obtained: %d\n",t); if (m1+m2<=66||p1+p2<=66||c1+c2<=66) { printf("Sorry, you've failed to pass."); } else if (t>=60) { printf("You've got 1st division."); } else if (t>=45) { printf("You've got 2nd division."); } else if (t>=33) { printf("You've got 3rd division."); } else { printf("Sorry, you've failed to pass."); } getch(); } Task-18: A program to display a Floyd’s triangle of 6 lines. #include<stdio.h> #include void main() { clrscr(); printf("1\n"); printf("2 3\n"); printf("4 5 6\n"); printf("7 8 9 10\n"); printf("11 12 13 14 15\n"); printf("16 17 18 19 20 21\n"); getch(); }

Task-19: A program to find out the sum of a series of numbers with user defined interval, first and last number. #include<stdio.h> #include void main() { clrscr(); long int i,j,k,l,s=0; printf("Enter the first number: "); scanf("%ld",&k); printf("Enter the increment: "); scanf("%ld",&l); printf("Enter the last number: "); scanf("%ld",&j); for(i=k;i<j+1;i=i+l) { s=s+i; } printf("The summation is : %ld",s); getch(); } Task-20: A program to find out the sum of all odd numbers between 1 and 100. #include<stdio.h> #include void main() { clrscr(); long int i,s=0; for(i=1;i<101;i=i+2) { s=s+i; } printf("The summation is : %ld",s); getch(); } Task-21: A program to find out the sum of a series of square of numbers with user defined interval, first and last number #include<stdio.h> #include

#include<math.h> void main() { clrscr(); long int i,j,k,l,s=0; printf("Enter the first number: "); scanf("%ld",&k); printf("Enter the increment: "); scanf("%ld",&l); printf("Enter the last number: "); scanf("%ld",&j); for(i=k;i<j+1;i=i+l) { s=s+pow(i,2); } printf("The summation is : %ld",s); getch(); } Task-22: A program to find out 12 + 22 + ..................................... + 992 = ? #include<stdio.h> #include #include<math.h> void main() { clrscr(); long int i,s=0; for(i=1;i<101;i=i+2) { s=s+pow(i,2); } printf("The summation is : %ld",s); getch(); } Task-23: A program to find out the factorial of n. #include<stdio.h> #include void main() { clrscr(); long int i,j,n; j=1;

printf("Enter the number: "); scanf("%ld",&n); if (n>0) { for (i=1;i #include void main() { clrscr(); int i,j,k=1,n; printf("Enter the number of lines to display: "); scanf("%d",&n); for (i=1;i
Task-25: A program to find out 1 + x + x2 + .............................. + xn = ? #include<stdio.h> #include #include<math.h> void main() { clrscr(); int x,n,i; long int s=0; printf("Enter the value of X: "); scanf("%d",&x); printf("Enter the value of N: "); scanf("%d",&n); for (i=0;i #include void main() { clrscr(); int i,j,k,n; printf("Enter how many lines to display: "); scanf("%d",&n); for (i=1;i
printf(" %d ",k); k=1; } } } else { k=0; for (j=0;j #include void main() { clrscr(); float mc,hc,co,lc,pr; printf("The price of Mill Cloth: "); scanf("%f",&mc); printf("The price of Hand Loom Cloth: "); scanf("%f",&hc); if (mc<=100) { mc=mc; } else if (mc<=200) { co=(mc*5)/100;

mc=mc-co; } else if (mc<=300) { co=(mc*7.5)/100; mc=mc-co; } else { co=(mc*10)/100; mc=mc-co; } if (hc<=100) { lc=(hc*5)/100; hc=hc-lc; } else if (hc<=200) { lc=(hc*7.5)/100; hc=hc-lc; } else if (hc<=300) { lc=(hc*10)/100; hc=hc-lc; } else { lc=(hc*15)/100; hc=hc-lc; } pr=hc+mc; printf("The total price of cloth is %.2f.",pr); getch(); } Task-28: A program that finds out if a number is prime or not. #include<stdio.h> #include void main() { clrscr(); int num,mod,i;

printf("Enter a number: "); scanf("%d",&num); if(num==0||num==1) { printf("The number is a prime number."); } else { for (i=2;i #include void main() { clrscr(); int ar[10],max=0,min,i; for(i=0;i<10;i++) { printf("Enter %dth number: ",i+1); scanf("%d",&ar[i]); if(max<ar[i]) { max=ar[i]; } } min=ar[0]; i=1; while(i<10)

{ if(min>ar[i]) { min=ar[i]; } i++; } printf("\n\n\n\t"); printf("The maximum value is %d.",max); printf("\n\tThe minimum value is %d.",min); getch(); } Task-30: A program to generate the table of square roots. #include<stdio.h> #include #include<math.h> void main() { clrscr(); float i,j,k; printf("\nNumber "); for(k=0;k<10;k++) { printf(" %.3f ",k/10); } printf("\n\n"); for(j=0;j<10;j++) { printf(" %.1f ",j); for(i=0;i<10;i++) { printf(" %.3f ",sqrt(j+i/10)); } printf("\n\n"); } getch(); } Task-31: A program to generate the multiplication table. #include<stdio.h> #include void main() {

clrscr(); int i,j; for(j=1;j<13;j++) { for(i=1;i<11;i++) { printf(" %d ",i*j); } printf("\n\n"); } getch(); } Task-32: A program to generate a table of 2-n

n

2n.

#include<stdio.h> #include void main() { clrscr(); float n,i,j,p,d=1; printf("Enter a value of N: "); scanf("%f",&n); printf("2^-n\tn\t2^n\n\n"); for(i=0;i #include void main() { clrscr(); float i,j,x,n,p,s=0; printf("Enter a value of X: ");

scanf("%f",&x); printf("Enter a value of N: "); scanf("%f",&n); if(x>-1&&x<1) { for(i=0;i

Related Documents

C Code Archive
November 2019 6
Archive
November 2019 45
Hamilton - Code C++
July 2020 1
Gray Code In C
June 2020 2
Code C (3).docx
April 2020 4