0% found this document useful (0 votes)
3 views14 pages

C Programming

Uploaded by

khushigill312
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views14 pages

C Programming

Uploaded by

khushigill312
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

C Programming All Programs Codes and Outputs

Tested By Adeshjeet! (Total 14 Program)

Last Updated on 19/10/2024

Program 1 (Hello World)


<code>

#include<stdio.h>

#include<conio.h>

void main() {

clrscr();

printf("Hello World!");

getch();

Output

Hello World!

------------------------------------------------------------------------------------------

Program 2 (Addition) // Adding 2 numbers


<code>

#include<conio.h>

void main() {

clrscr();

int a,b,sum;

printf("\nEnter 1st Number:");


scanf("%d",&a);

printf("\nEnter 2nd Number:");

scanf("%d",&b);

sum=a+b;

printf("\nSum = %d",sum);

getch();

Output

Enter 1st Number:5

Enter 2nd Number:10

Sum = 15

------------------------------------------------------------------------------------------

Program 3 (Subtracting 2 Numbers)


<code>

#include<stdio.h>

#include<conio.h>

void main() {

clrscr();

int a,b,sub;

printf("\nEnter 1st Number:");

scanf("%d",&a);

printf("\nEnter 2nd Number:");

scanf("%d",&b);

sub=a-b;

printf("\nSubtraction = %d",sub);
getch();

Output

Enter 1st Number:15

Enter 2nd Number:20

Subtraction = -5

------------------------------------------------------------------------------------------

Program 4 (Multiplication)
<code>

#include<stdio.h>

#include<conio.h>

void main()

int a,b,mul;

clrscr();

printf("enter the value of a=")

scanf ("%d",&a);

printf("enter the value of b=")

scanf("%d",&b);

mul=(a*b);

printf("mul=%d",mull);

getch();

Output

enter the value of a=15


enter the value of b=20

mul=300

------------------------------------------------------------------------------------------

Program 5 (Devision)
<code>

#include<stdio.h>

#include<conio.h>

void main()

int a,b,div;

clrscr();

printf("enter the value of a=");

scanf("%d",& a);

printf("enter the value of b=");

scanf("%d",& b);

div=a/b;

printf("division=%d",div);

getch();

Output

enter the value of a=32

enter the value of b=16

division=2

------------------------------------------------------------------------------------------
Program 6 (Average of 3 Numbers)
<code>

#include<stdio.h>

#include<conio.h>

void main() {

int a,b,c;

float avg;

clrscr();

printf("a=");

scanf("%d",&a);

printf("b=");

scanf("%d",&b);

printf("c=");

scanf("%d",&c);

avg=(a+b+c/3);

printf("avg=%f",avg);

getch();

Output

a=5

b=10

c=15

avg=20.000000

------------------------------------------------------------------------------------------
Program 7 (All Arthamatics Program)
<code>

#include<stdio.h>

#include<conio.h>

void main(){

clrscr();

int a=25,b=5;

printf("\na+b = %d",a+b);

printf("\na-b = %d",a-b);

printf("\na*b = %d",a*b);

printf("\na/b = %d",a/b);

printf("\na%b = %d",a%b);

printf("\na+1 = %d",++a);

printf("\nb-1 = %d",--b);

getch();

Output

a+b = 30

a-b = 20

a*b = 125

a/b = 5

a%b = 0

a+1 = 26

b-1 = 4

------------------------------------------------------------------------------------------
Program 8 (Relational Operators)
<code>

#include<stdio.h>

#include<conio.h>

void main()

int a=24,b=7;

clrscr();

printf("a<b:%d\n",a<b);

printf("a>b:%d\n",a>b);

printf("a<=b:%d\n",a<=b);

printf("a>=b:%d\n",a>=b);

printf("a==b:%d\n",a==b);

printf("a!=b:%d\n",a!=b);

getch();

Output

a<b:0

a>b:1

a<=b:0

a>=b:1

a==b:0

a!=b:1

------------------------------------------------------------------------------------------
Program 9 (Assignment Operators)
<code>

#include<stdio.h>

#include<conio.h>

void main()

int a=10;

printf("Value of a is %d\n",a);

a+=10;

printf("Value of a is %d\n",a);

a-=10;

printf("Value of a is %d\n",a);

a*=10;

printf("Value of a is %d\n",a);

a/=10;

getch();

Output

Value of a is 10

Value of a is 20

Value of a is 10

Value of a is 100

------------------------------------------------------------------------------------------

Program 10 (For Loop)


<code>

#include<stdio.h>

#include<conio.h>

void main()

int i=0;

clrscr();

for (i=1;i<10;i++)

printf("hello world\n");

getch();

Output

hello world

hello world

hello world

hello world

hello world

hello world

hello world

hello world

hello world

------------------------------------------------------------------------------------------
Program 11 (While Loop)
<code>

#include<stdio.h>

#include<conio.h>

void main()

int i=2;

clrscr();

while (i<=10)

printf("hello word\n");

i++;

getch();

Output

hello word

hello word

hello word

hello word

hello word

hello word

hello word

hello word

hello word
------------------------------------------------------------------------------------------

Program 12 (Do While Loop)


<code>

#include<stdio.h>

#include<conio.h>

int main()

int i=10;

do

printf("%d",i);

i--;

while(i>=1);

getch();

return 0;

Output

10987654321

------------------------------------------------------------------------------------------

Program 13 (Function Call / Swap)


<code>

#include<stdio.h>

#include<conio.h>
int sum(int a, int b)

return a+b;

int main(){

clrscr();

int add=sum(10, 20);

printf("Sum is %d", add);

getch();

return 0;

Output

Sum is 30

------------------------------------------------------------------------------------------

Program 14 (Switch)
<code>

#include<stdio.h>

#include<conio.h>

void main() {

int ch;

clrscr();

int i=2;

printf("Enter Your choice:");

scanf("%d",&ch);
switch(ch)

case 1:

printf("Monday\n");

break;

case 2:

printf("Tuesday\n");

break;

case 3:

printf("Wednessday\n");

break;

case 4:

printf("Thursday\n");

break;

case 5:

printf("Friday");

break;

case 6:

printf("Saturday");

break;
case 7:

printf("Sunday");

deafult:

printf("Error! Please Select Number Between 1-7");

break;

i++;

getch();

Output

Enter Your choice:5

Friday

------------------------------------------------------------------------------------------

You might also like