Beruflich Dokumente
Kultur Dokumente
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
getch ();
}
1
2.write a program to Switch
#include<stdio.h>
#include<conio.h>
intmain() {
charoperator;
floatnum1,num2;
switch(operator) {
case'+':
printf("%.2f + %.2f = %.2f",num1, num2, num1+num2);
break;
case'-':
printf("%.2f - %.2f = %.2f",num1, num2, num1-num2);
break;
case'*':
printf("%.2f * %.2f = %.2f",num1, num2, num1*num2);
break;
case'/':
printf("%.2f / %.2f = %.2f",num1, num2, num1/num2);
break;
default:
printf("ERROR: Unsupported Operation");
}
getch();
}
2
3. write a program toSource Code to Find Transpose of a Matrix
#include <stdio.h>
#include<conio.h>
void main()
{
int a[10][10], trans[10][10], r, c, i, j;
printf("Enter rows and column of matrix: ");
scanf("%d %d", &r, &c);
3
4
4. write a Program to Check Even or Odd
#include<stdio.h>
#include<conio.h>
Void main()
{
int number;
getch;
}
5
5. write a program to Structure program
#include <stdio.h>
#include <string.h>
#include<conio.h>
struct Books {
char title[50];
char author[50];
char subject[100];
intbook_id;
};
int main( ) {
/* book 1 specification */
strcpy( Book1.title, "C Programming");
strcpy( Book1.author, "Nuha Ali");
strcpy( Book1.subject, "C Programming Tutorial");
Book1.book_id = 6495407;
/* book 2 specification */
strcpy( Book2.title, "Telecom Billing");
strcpy( Book2.author, "Zara Ali");
strcpy( Book2.subject, "Telecom Billing Tutorial");
Book2.book_id = 6495700;
getch();
}
6
7
6. write a program to union
#include <stdio.h>
#include <string.h>
#include<conio.h>
union Data {
int i;
float f;
charstr[20];
};
int main( ) {
getch();
}
8
7. write a program to check perfect number
#include<stdio.h>
#include<conio.h>
void main(){
int n,i=1,sum=0;
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);
getch();
}
9
8. write a program to Farenhite to Celsius
#include<stdio.h>
#include<conio.h>
main()
{
float fh,cl;
printf("Enter temperature value in Fahrenheit: ");
scanf("%f", &fh);
cl = (fh - 32) / 1.8;
printf("Converted Celsius value: %f",cl);
getch();
return 0;
}
//CALL BY REFERENCE
voidcall_by_reference(int *y) {
printf("Inside call_by_reference y = %d before adding 10.\n", *y);
(*y) += 10;
printf("Inside call_by_reference y = %d after adding 10.\n", *y);
getch();
}
10
9. write a program toLeap Year
#include <stdio.h>
#include<conio.h>
void main()
{
int year;
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
getch();
}
11
10. write a program to Fibanacci series
#include <stdio.h>
#include<conio.h>
void main()
{
int i, n, t1 = 0, t2 = 1, nextTerm = 0;
12
11. write a program to Decimal to binary
#include<stdio.h>
#include<conio.h>
void main(){
int binaryNumber[100],i=1,j;
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
printf("%d",binaryNumber[j]);
getch();}
13
14
12. write a program to Source Code to Calculate Average Using Arrays
#include <stdio.h>
#include<conio.h>
void main(){
int n, i;
floatnum[100], sum=0.0, average;
printf("Enter the numbers of data: ");
scanf("%d",&n);
while (n>100 || n<=0)
{
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d",&n);
}
for(i=0; i<n; ++i)
{
printf("%d. Enter number: ",i+1);
scanf("%f",&num[i]);
sum+=num[i];
}
average=sum/n;
printf("Average = %.2f",average);
getch();
}
15
13. write a program to Addition of All Elements of the Array
#include<stdio.h>
#include<conio.h>
void main() {
int i, arr[50], sum, num;
//Computation of total
sum = 0;
for (i = 0; i <num; i++)
sum = sum + arr[i];
//Printing of total
printf("\nSum=%d", sum);
getch();
}
16
14. write a program to Factorial using recursion
#include<stdio.h>
int fact(int);
int main(){
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
return 0;
}
17
15. write a program to Swap using Functions
#include <stdio.h>
#include<conio.h>
int main()
{
int x, y;
swap(&x, &y);
return 0;
}
temp = *b;
*b = *a;
*a = temp;
getch();
}
18
16. write a program to Matrix Multiplication
#include <stdio.h>
#include<conio.h>
void main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
if (n != p)
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");
multiply[c][d] = sum;
sum = 0;
}
}
printf("\n");
}
}
getch();
}
19
20
17. write a program to Sum of 5 subject marks
#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c,d,e,total;
clrscr();
printf("enter English marks");
scanf("%d",&a);
printf("enter Hindi marks");
scanf("%d",&b);
printf("enter SST marks");
scanf("%d",&c);
printf("enter Computer marks");
scanf("%d",&d);
printf("enter Science marks");
scanf("%d",&e);
total=a+b+c+d+e;
printf("sum =%d",total);
getch();
}
21
18. write a program to Give the value at run time to check Prime No.
#include<stdio.h>
#include<conio.h>
void main()
{
intn,i,c=0;
clrscr();
printf("enter a number");
scanf("%d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{c++;
break;
}
}
if(c==0&& n!=1)
printf("%d is a prime number",n);
else
printf("%%d isnot a prime number",n);
getch();
}
22
19. write a program to Find the Greatest number using Array
#include<stdio.h>
#include<conio.h>
void main()
{
inti,a[10];l=0;
clrscr();
printf("enter the numbers: ");
for(i=1;i<=10; i++)
{
scanf("%d",& a[i]);
}
for(i=1;i<=10;i++)
{
if(a[i]>l)
{
l=a[i]];
}
printf("\n the largest number is=%d",l);
getch();
}
23
20. write a program to Call by Address in function
#include<stdio.h>
#include<conio.h>
int max(int num1,int num2);
void main()
{
inta,b,ret;
a=100;
b=200;
ret=max(a,b);
printf("max value is=%d \n",ret);
getch();
}
int max(int num1,int num2)
{
int result:
if(num1>num2)
result=num1;
else
result=num2;
return result;
}
24
21.write a program to Prime number using Function-
#include<stdio.h>
#include<conio.h>
main()
{
intn,result;
printf("enter a number to check whether it is prime or not.\n");
scanf("%d",&n);
result=check_prime(n);
if(result==1)
printf("%d is prime number. \n",n);
else
printf("%d is not a prime number. \n",n);
return 0;
}
intcheck_prime(int a)
{
int c;
for(c=2;c<=a-1;c++)
{ if(a%c==0)
return 0;
}
if(c==a)
return 1;
getch();
}
25
22-write a program to insert operation in binary search tree
#include<stdio.h>
#include<stdlib.h>
struct node
{
int key;
struct node *left, *right;
};
26
insert(root, 70);
insert(root, 60);
insert(root, 80);
return 0;
}
27
23- write a program to for Stack in C
#include <stdio.h>
#include <conio.h>
#define max 5
void main()
{
//... create stack
int stack[max],data;
inttop,option,reply;
//... init stack
top = -1;
clrscr();
do
{
printf("\n 1. push");
printf("\n 2. pop");
printf("\n 3. exit");
printf("\nSelect proper option : ");
scanf("%d",&option);
switch(option)
{
case 1 : // push
printf("\n Enter a value : ");
scanf("%d",&data);
reply = push(stack,&top,&data);
if( reply == -1 )
printf("\nStack is full");
else
printf("\n Pushed value");
break;
case 2 : // pop
reply = pop ( stack,&top,&data);
if( reply == - 1)
printf("\nStack is empty");
else
printf("\n Popped value is %d",data);
28
break;
case 3 : exit(0);
} // switch
}while(1);
} // main
int push( int stack[max],int *top, int *data)
{
if( *top == max -1 )
return(-1);
else
{
*top = *top + 1;
stack[*top] = *data;
return(1);
} // else
} // push
int pop( int stack[max], int *top, int *data)
{
if( *top == -1 )
return(-1);
else
{
*data = stack[*top];
*top = *top - 1;
return(1);
} //else
29
23- Write a program to pointer
#include <stdio.h>
int main()
{
int *ptr, q;
q = 50;
/* address of q is assigned to ptr */
ptr = &q;
/* display q's value using ptr variable */
printf("%d", *ptr);
return 0;
}
30
24- Write a program to insertion short
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t;
d--;
}
}
return 0;
}
31