Professional Documents
Culture Documents
#include<stdio.h>
void main()
{
int p,r,t;
float i;
printf("Enter the Principal, Rate and Time\n");
scanf("%d %d %d",&p,&r,&t);
i=p*r*t/100;
printf("simple interest is : %f",i);
#include<stdio.h>
void main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swap a=%d b=%d",a,b);
}
1
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
#include <stdio.h>
void main()
{
int A, B, C;
else
printf("%d is the largest number.", C);
}
#include<stdio.h>
int main()
{
int n,sum=0,m;
printf("Enter a number:");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
printf("Sum is=%d",sum);
return 0;
}
2
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);
for(i=2;i<number;++i)
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
int originalNum, num, lastDigit, digits, sum;
printf("Enter any number to check Armstrong number: ");
scanf("%d", &num);
sum = 0;
originalNum = num;
3
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
while(num > 0)
{
lastDigit = num % 10;
if(originalNum == sum)
{
printf("%d is ARMSTRONG NUMBER", originalNum);
}
else
{
printf("%d is NOT ARMSTRONG NUMBER", originalNum);
}
return 0;
}
#include<stdio.h>
int main(){
int num,i,count,n;
printf("Enter max range: ");
scanf("%d",&n);
for(num = 1;num<=n;num++){
count = 0;
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
4
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
return 0;
}
#include <stdio.h>
int main()
scanf("%d",&number);
scanf("%d",&array[c]);
scanf("%d",&search);
if ( array[c] == search {
break;
if ( c == number )
5
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
return 0;
#include <stdio.h>
#include <conio.h>
void main()
clrscr();
scanf("%d", &a[i][j]);
6
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
scanf("%d", &b[i][j]);
printf("%d\t", c[i][j]);
printf("\n");
7
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
getch();
10) write a c program that uses functions to perform the multipliction of matrices
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
clrscr();
printf("enter the number of row=");
scanf("%d",&r);
printf("enter the number of column=");
scanf("%d",&c);
printf("enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("multiply of the matrix=\n");
for(i=0;i<r;i++)
{
8
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[50], str2[50];
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
strcat(str1, str2);
printf("\nString after concatenation is:\n%s", str1);
getch();
return 0;
}
12)write a c program for length of string with and without string handling functions
9
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
#include <stdio.h>
int main()
{
char str[100];
int i,length=0;
.
for(i=0; str[i]!='\0'; i++)
{
length++;
}
return 0;
}
13) write a c program to demonstrate call by value and call by reference mechanism
a) call by value:
#include <stdio.h>
void swap(int , int);
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function a = %d, b = %d\n",a,b);
}
10
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
b)call by reference
#include <stdio.h>
void swap(int *, int *);
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b);
}
#include<stdio.h>
gcd = findGCD(num1,num2);
printf("\n The GCD of %d and %d is: %d\n\n",num1,num2,gcd);
return 0;
11
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
#include <stdio.h>
int main()
int a = 22;
int *p = &a;
p++;
p--;
float b = 22.22;
12
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
float *q = &b;
q++;
q--;
char c = 'a';
char *r = &c;
r++;
r--;
return 0;
16) write a c program to demonstrate dynamic arrays using dynamic memory management
functions
13
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
#include <stdio.h>
#include <stdlib.h>
int main()
Int *ptr;
int size;
scanf("%d", &size);
if (ptr == NULL) {
else {
ptr[j] = j + 1;
14
Department of Computer Science A.S.N Degree College, Tenali
Programming in c I B.S.C
return 0;
15
Department of Computer Science A.S.N Degree College, Tenali