You are on page 1of 13

/*Print the numbers from 1 to 10 with their squares*/ PROGRAM: #include<stdio.h> #include <stdio.h> #include<conio.

h> void main() { int i; clrscr(); printf(“\n The numbers with their squares is: \n”); for(i = 1; i <= 10; i = i + 1) printf("%d = %d \n", i, i * i); getch();
}

OUTPUT The numbers with their squares is: 1=1 2=4 3=9 4 = 16 5 = 25 6 = 36 7 = 49 8 = 64 9=8 .

h> #include <conio. scanf("%d".sum).do while loop\n2.&op). ++count. } while(count<=n).op.&n). switch(op) { case 1: count=1.h> void main() { int n. do { sum+=count. do-while*/ PROGRAM: #include <stdio. printf("\n Enter your choice\n1./*Sum of ‘n’ numbers using for. scanf("%d". printf("\n\nSum = %d".for loop: "). clrscr(). . count. printf("Enter an integer: "). sum=0.

default: printf("\n\n Invalid Option").sum). case 2: for(count=1. } getch().break. } printf("\n\nSum = %d". } . break.count<=n.++count) { sum+=count.

OUTPUT Enter an integer: 15 Enter your choice 1. do while loop 2. for loop 1 Sum = 120 .

num.h> #include <conio. printf("\n\nFactorial of %d is: %d"./*Factorial of a given number using functions*/ PROGRAM: #include<stdio. getch(). i<=n. return f. } . clrscr().fact).h> void main() { int i. for(i=1.fact.num. scanf("%d". fact = factorial(num). printf("Enter a number: "). int factorial(int). } int factorial(int n) { int i. i++) f=f*i.f=1.&num).

OUTPUT Enter a number: 5 Factorial of 5 is: 120 .

&b).a. printf("\n In call by reference.b). printf("\n In call by value.&a. after swapping result is:\n a=%d \t b=%d ".a. } void swap1(int x. scanf("%d%d". clrscr().b).b). printf("\nBefore swapping result is: \n a=%d \t b=%d\n". int).h> #include<conio. void swap2(int *x. after swapping result is:\n a=%d \t b=%d \n". getch(). void swap1(int. int y) { int t.b). swap2(&a. t=x./*swap two numbers using call by value and call by reference*/ PROGRAM: include<stdio. .int *y).&b). printf("Enter the value of a and b").b.h> void main() { inta. swap1(a.a.

x=y.int *y) { int t. y=t. } . *x=*y. t=*x. *y=t. } void swap2(int *x.

after swapping result is: a=40 b=70 In call by reference. after swapping result is: a=70 b=40 .OUTPUT Enter the value of a and b 40 70 Before swapping result is: a=40 b=70 In call by value.

scanf("%d".i<n. printf("How many elements:"). clrscr(). printf("Enter the Array:"). if(a[i]<small) small=a[i].large.i<n.&a[i]).i. for(i=0. for(i=1.small.&n).n.h> #include<conio.large).++i) scanf("%d". ./*smallest and largest element in an array*/ PROGRAM: #include<stdio. } printf("The largest element is %d". large=small=a[0].h> void main() { int a[50].++i) { if(a[i]>large) large=a[i].

} . getch().printf("\nThe smallest element is %d".small).

OUTPUT How many elements: 6 Enter the Array: 98 65 23 87 54 21 The largest element is 98 The smallest element is 21 .