43) Sample C Program to print upper triangle.
# include <stdio.h>
# include <conio.h>
main( )
{
int a[4][4], i, j, c;
clrscr( );
printf("Enter the no. for which you want upper triangle:");
scanf("%d", &c);
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
if(i < j)
a[i][j] = c;
else
a[i][j] = 0;
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
{
printf("%d:", a[i][j]);
printf('\n');
}
getch( );
}
44) Sample C Program to accept two 3 dimensional array and store addition of those into the third 3-D array .
# include <stdio.h>
# include <conio.h>
main( )
{
int a[3][3], b[3][3], c[3][3], i, j;
clrscr( );
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
{
printf("Enter the two values for a[%d][%d] & b[%d][%d]", i, j, i, j);
scanf("%d %d", &a[i][j], &b[i][j]);
}
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
c[i][j] = a[i][j] + b[i][j];
printf("%d", c[i][j]);
}
printf('\n');
}
getch( );
}
45) Sample C Program to accept a string and find the length of the given string by using functions.
# include <stdio.h>
# include <conio.h>
main( )
{
char str[80];
int length;
clrscr( );
printf("Enter a string:");
length = getline(str);
printf("Length of the given string is %d", length);
getch ( );
}
int getline(char str[])
{
int i;
for(i = 0; i < 80 && ( ( str[i] = getchar( ) )! = '\n' ); i++);
if(str[i] == '\n')
str[i] = '\0';
return i;
}
ALSO CHECK THESE C PROGRAMS:
- C Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text.
- C Program to accept two string and compare the strings are equal or not.
- C Program to sort the entered numbers using bubble sort.
- C Program To Implement Minimum Spanning Tree Using Functions, Pointers & Structures.
- C Program To Implement 8 Queens Problem Using Arrays, Pointers & Functions.
- C Program To Implement Quick Sort Using Pointers, Functions & Arrays.
...Back To C Program Index.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com