0% found this document useful (0 votes)
42 views

C Programs PDF

The document contains 15 C programming examples including a simple calculator, compound interest and amount calculator, temperature converter, swapping values without a third variable, password input with asterisks, string manipulation, number counting, binary number printing, system configuration check, quadratic equation solver, vowel/consonant identifier, name printing as ASCII, adding numbers in a loop, system shutdown command, and odd/even number tester. Each example contains the full source code to demonstrate the programming concept.

Uploaded by

Nita kumal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

C Programs PDF

The document contains 15 C programming examples including a simple calculator, compound interest and amount calculator, temperature converter, swapping values without a third variable, password input with asterisks, string manipulation, number counting, binary number printing, system configuration check, quadratic equation solver, vowel/consonant identifier, name printing as ASCII, adding numbers in a loop, system shutdown command, and odd/even number tester. Each example contains the full source code to demonstrate the programming concept.

Uploaded by

Nita kumal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

C-program

Examples
Akhil Prazapati.
9817558662
akhilprajapati62@gmail.com

NEPAL COLLEGE OF
INFORMATION TECHNOLOGY
(1) Simple Calculator
• #include<stdio.h>
• #include<conio.h>
• main()
• {
• float num1, num2;
• char sign;
• float result;
• printf("Enter the first number: ");
• scanf("%f",&num1);
• printf("Enter the operator: ");
• scanf("%c",&sign);
• printf("Enter the second number: ");
• scanf("%f",&num2);
• switch(sign)
• {
• case '+':
• result=num1+num2;
• printf("%f",result);
• break;
• case '-':
• result=num1-num2;
• printf("%f",result);
• break;
• case '*':
• result=num1*num2;
• printf("%f",result);
• break;
• case '/':
• result= num1/num2;
• printf("%f",result);
• break;
• }
• getch();
• }
(2) CI and CA
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
• int main()
• {
• /*CI=P((1+R/100)^T-1) */
• /*CA=P+CI */

• float principle, time, rate, CI, CA;


• printf("Enter Principle Amount in NC(RS)\n");
• scanf("%f",&principle);
• printf("Enter Time in year\n");
• scanf("%f",&time);
• printf("Enter Rate of Intrest in per anum\n");
• scanf("%f",&rate);
• CI=principle*(pow((1+rate/100),time)-1);
• CA=principle+CI;
• printf("Your Compound Intrest is %f\n",CI);
• printf("Your Compound Amount is %f",CA);
• getch();
• }
(3) Temperature Converter
• #include<stdio.h>
• #include<conio.h>
• main()
• {
• float c, f, c1, f1;
• clrscr();
• printf("Enter the celcius temperature\n");
• scanf("%f",&c);
• f1=((180*c)/100)-32;
• printf("The fernhite temperature is %f\n",f1);
• printf("Enter the fernhite temperature \n");
• scanf("%f",&f);
• c1=((f-32)*100)/180;
• printf("The celcius temperature is %f\n",c1);
• getch();
• }
(4) Swapping Value
• /* NOTE: “Without third variable” */
• #include<stdio.h>
• #include<conio.h>
• main()
• {
• int x, y;
• printf("Enter the value of x\n");
• scanf("%d",&x);
• printf("Enter the value of y\n");
• scanf("%d",&y);
• x=x+y;
• y=x-y;
• x=x-y;
• printf("The value of x is %d\n",x);
• printf("The value of y is %d\n",y);
• getch();
• }
(5) Password Showing
• #include<stdio.h>
• #include<conio.h>
• main()
• {
• char email[30];
• char password[10];
• char ch;
• int i;
• printf("Enter email address\n");
• gets(email);
• printf("Enter the password\n");
• for(i=0;i<9;i++)
• {
• ch=getch();
• password [i]=ch;
• ch='*';
• printf("%c",ch);
• }
• password[i]='\0';
• printf("\n\n email is : %s",email);
• printf("\n your password is %s",password);
• getch();
• }
(6) String Works
• #include<stdio.h>
• #include<conio.h>
• #include<string.h>
• int main()
• {
• char name1[30], name2[33], name;
• int length1, length2, length;
• printf("Enter your first name\n");
• gets(name1);
• printf("Enter your second name\n");
• gets(name2);
• length1=strlen(name1);
• length2=strlen(name2);
• length=length1+length2;
• printf("Your first name consists of %d letters\n",length1);
• printf("Your second name consists of %d letters\n",length2);
• printf("Your full name consists of %d letters\n",length);
• strcat(name1,name2);
• printf("Your full name is %s\n",name1);
• strrev(name1);
• printf("The reverse of your full name is %s\n",name1);
• }
(7) Number Counting
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
• int main()
• {
• float principle, time, rate, CI, CA;
• int count;
• int bit;
• int n;
• printf("\n Hello friend you are welcome in LKG,\n\n How much you have to count ?\n");
• scanf("%d",&n);
• for(count=1;count<=n;count++)
• {
• printf("%d ",count);
• }
• getch();
• }
(8) Print n-Bits
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
• int main()
• {
• float principle, time, rate, CI, CA;
• int count;
• int bit;
• int n;
• printf("\n Hello friend! you are welcome,\n\n How many bits do you need ?\n");
• scanf("%d",&n);
• for(count=1;count<=n;count++)
• {
• printf("%d ",count%2);
• }
• getch();
• }
(9) System configuration
• #include<stdio.h>
• #include<conio.h>
• #include<stdlib.h>
• int main()
• {
• system("C:\\Windows\\System32\\ipconfig");
• getch();
• }
(10) Solve “ax^2+bx+c=0”
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
• int main()
• {
• int a;
• int b;
• int c;
• float k;
• float root1, root2;
• printf("Enter the co-efficients of x^2\n");
• scanf("%d", &a);
• printf("Enter the co-efficients of x\n");
• scanf("%d",&b);
• printf("Enter the co-efficients of constant\n");
• scanf("%d",&c);

• k=(b*b)-(4*a*c);
• root1=(-b+pow(k,0.5))/(2*a);
• root2=(-b-pow(k,0.5))/(2*a);

• printf("The first solution is %3f\n",root1);


• printf("The second solution is %3f\n",root2);
• getch();
• }
(11) Vowel and consunant
• #include<stdio.h>
• #include<conio.h>
• int main()
• {
• char letter;
• printf("You may enter any Capital-letter or Small-letter\n");
• scanf("%c",&letter);
• switch(letter)
• {
• case'a':
• case'e':
• case'i':
• case'o':
• case'u':
• case'A':
• case'E':
• case'I':
• case'O':
• case'U':

• printf("Your letter (%c) is the the vowel letter",letter);


• break;
• default:
• printf("Your letter (%c) is the the consunant letter",letter);

• }
• getch();
• }
(12) My Name ASCII
• #include<stdio.h>
• #include<conio.h>
• #include<math.h>
• int main()
• {
• int a=65;
• int b=75;
• int c=72;
• int d=73;
• int e=76;
• printf("\nMy name is %c%c%c%c%c\n",a,b,c,d,e);
• getch();
• }

• The output is like this:


(13) Add n numbers
• #include<stdio.h>
• #include<conio.h>
• int main()
• {
• int n;
• int i=0;
• int sum=0;
• printf("Enter the value upto which to add\n");
• scanf("%d",&n);

• for (i=0;i<=n;i++) /*loop*/


• {
• sum=sum+i;
• }
• printf("The sum is %d",sum);
• getch();
• }
(14) Shut-down
• #include <stdio.h>
• #include <stdlib.h>
• int main()
• {
• system("C:\\WINDOWS\\System32\\shutdown /s");
• return 0;
• }
(15) Odd or Even Test
• #include<stdio.h>
• #include<conio.h>
• #include<string.h>
• int main()
• {
• int a, b;
• printf("Enter first number\n");
• scanf("%d",&a);
• if(a%2==0)
• printf("The number is even\n");
• else
• printf("The number is odd\n");
• printf("\nEnter second number\n");
• scanf("%d",&b);
• if(b%2==0)
• printf("The number is even\n");
• else
• printf("The number is odd\n");
• getch();
• }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy