C program to find the
largest element in an array
#include<stdio.h>
int main(){
int a[50],size,i,big;
printf("\nEnter
the size of the array: ");
scanf("%d",&size);
printf("\nEnter
%d elements in to the array: ”, size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
big=a[0];
for(i=1;i<size;i++){
if(big<a[i])
big=a[i];
}
printf("\nBiggest:
%d",big);
return 0;
}
C program to print Pascal triangle using for
loop
#include<stdio.h>
long fact(int);
int main(){
int
line,i,j;
printf("Enter
the no. of lines: ");
scanf("%d",&line);
for(i=0;i<line;i++){
for(j=0;j<line-i-1;j++)
printf(" ");
for(j=0;j<=i;j++)
printf("%ld ",fact(i)/(fact(j)*fact(i-j)));
printf("\n");
}
return 0;
}
long fact(int num){
long f=1;
int i=1;
while(i<=num){
f=f*i;
i++;
}
return f;
}
Concatenation of two strings using
pointer in c programming language
#include<stdio.h>
int main(){
int i=0,j=0;
char *str1,*str2,*str3;
puts("Enter first
string");
gets(str1);
puts("Enter second
string");
gets(str2);
printf("Before
concatenation the strings are\n");
puts(str1);
puts(str2);
while(*str1){
str3[i++]=*str1++;
}
while(*str2){
str3[i++]=*str2++;
}
str3[i]='\0';
printf("After
concatenation the strings are\n");
puts(str3);
return 0;
}
0 comments:
Post a Comment