0% found this document useful (0 votes)
5 views2 pages

C Programs Collection

The document contains several C programs demonstrating basic programming concepts such as calculating simple interest, factorial of a number, finding the largest of three numbers, determining string length without built-in functions, performing 2D matrix addition, and calculating sum and standard deviation. Each program includes sample output to illustrate its functionality. These examples serve as practical applications of fundamental programming techniques.

Uploaded by

tejashwini.r1909
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)
5 views2 pages

C Programs Collection

The document contains several C programs demonstrating basic programming concepts such as calculating simple interest, factorial of a number, finding the largest of three numbers, determining string length without built-in functions, performing 2D matrix addition, and calculating sum and standard deviation. Each program includes sample output to illustrate its functionality. These examples serve as practical applications of fundamental programming techniques.

Uploaded by

tejashwini.r1909
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

Simple Interest

C Program:
#include <stdio.h>
int main() {
float p,r,t,si;
scanf("%f %f %f",&p,&r,&t);
si=(p*r*t)/100;
printf("Simple Interest = %.2f",si);
return 0;
}

Sample Output:
Simple Interest = 100.00

Factorial of a Number
C Program:
#include <stdio.h>
int main() {
int n,i; long long fact=1;
scanf("%d",&n);
for(i=1;i<=n;i++) fact*=i;
printf("Factorial = %lld",fact);
return 0;
}

Sample Output:
Factorial = 120

Largest of Three Numbers (Nested if)


C Program:
#include <stdio.h>
int main() {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
if(a>c) printf("%d",a);
else printf("%d",c);
} else {
if(b>c) printf("%d",b);
else printf("%d",c);
}
return 0;
}

Sample Output:
Largest = 45

String Length Without Built-in


C Program:
#include <stdio.h>
int main(){
char str[100]; int i=0,len=0;
gets(str);
while(str[i]!='\0'){ len++; i++; }
printf("Length = %d",len);
return 0;
}

Sample Output:
Length = 5

2D Matrix Addition
C Program:
#include <stdio.h>
int main(){
int a[2][2],b[2][2],s[2][2],i,j;
for(i=0;i<2;i++)
for(j=0;j<2;j++) scanf("%d",&a[i][j]);
for(i=0;i<2;i++)
for(j=0;j<2;j++) scanf("%d",&b[i][j]);
for(i=0;i<2;i++)
for(j=0;j<2;j++) s[i][j]=a[i][j]+b[i][j];
for(i=0;i<2;i++){
for(j=0;j<2;j++) printf("%d ",s[i][j]);
printf("\n");
}
return 0;
}

Sample Output:
6 8
10 12

Sum and Standard Deviation


C Program:
#include <stdio.h>
#include <math.h>
int main(){
int n,i; float x[10],sum=0,mean,var=0,sd;
scanf("%d",&n);
for(i=0;i<n;i++){ scanf("%f",&x[i]); sum+=x[i]; }
mean=sum/n;
for(i=0;i<n;i++) var+=(x[i]-mean)*(x[i]-mean);
sd=sqrt(var/n);
printf("Sum=%.2f SD=%.2f",sum,sd);
return 0;
}

Sample Output:
Sum=60.00 SD=8.16

You might also like