List of C Programs that makes u understand concepts in an easy fashion(Part2)



In Part 1 of this Ready Solution Kit, we have taken in to consideration, program based on Loops mostly. Here goes various implementations for Arrays(1-D and 2-D), Character Array, Switch, Sorting(Bubble Sort & Selection Sort) etc.

Program  9 Ask for month number and printf how many days

main()
{
int month;
clrscr();

printf("Enter Month Number:");
scanf("%d",&month);

switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("There are 31 Days");
break;
case 2:
printf('THere are 28 or 29 Days");
break;
case 4:
case 6:
case 9:
case 11:
printf("THere are 30 Days");
break;
default:
printf("Invalid Month Value");
}
getch();
}


Program 10: Program to determine greater among three numbers

main()
{
int a,b,c;
clrscr();

printf("Enter First Number;");
scanf("%d",&a);

printf("Enter Second Number;");
scanf("%d",&b);

printf("Enter Third Number:");
scanf("%d",&c);

if ((a>b) && (a>c))
printf("First Number is greater");

if ((b>a) && (b>c))
printf("Second Number is greater");

if ((c>a) && (c>b))
printf("Third Number is greater");

getch();
}

Program 11 Check whether entered number is EVEN, ODD POSITIVE or NEGATIVE

main()
{
int num;
clrscr();
printf("Enter Any Number:");
scanf("%d",&num);
if (num>0)
printf("Number is Positive");
else
printf("Number is Negative");
if (num%2==0)
printf("Number is EVEN");
else
printf("Number is ODD");

getch();
}

Program 12 : Program to illustrate basic working in Character array

main()
{
char str[80];
int l,w;
printf("Enter Any String");
fflush(stdin);
getch(str);

printf("Counting Length of String");
getch();
i=0;
while(str[i]!='\0')
{
l=l+1;
}
printf("Length of String %d",l);
getch();

printf("Counting No. of Words,'wait'");

getch();

l=0;w=0;

while(1)
{
if((str[l]==' '))
w=w+1;
l=l+1;
if(str[l]=='\0')
{
w=w+1;
break;
}
}
printf("Total Number of Words %d",w);

getch();


clrscr();

printf("COunting Vowels in the String ");
getch();

l=0;w=0;
while(str[l]!='\0')
{
switch(str[l])
{
case 'A' :
case 'E':
case  'I':
case 'O':
case 'U':
w=w+1;
break;
}
l=l+1;
}
printf(" Number of CAPITAL VOWELS %d",w);
getch();

clrscr();

printf("ENCRYPTING STRING");
getch();
l=0;
while(str[l]!='\0')
{
str[l]=str[l]+50;
l=l+1;
}
printf("Encrypted String is %s",str);
getch();

printf("Reverse Printing the String");

l=0;
while(str[l]!='\0')
{
l=l+1;
}
l=l-1;
while(l>0)
{
printf("%c",str[l]);
l=l-1;
}
getch();
}


Program 13: Program to TOGGLE CASE an already available String

main()
{
char str[]="Softech Computers, make Dreams True");
int i;
clrscr();
printf("Toggling the Available String");
getch();

i=0;

while(str[i]!='\0')
{
if((str[i]>=65) && (str[i]<=90))
{
str[i]=str[i]+32;
}
else
{
str[i]=str[i]-32;
}
i=i+1;
}

printf("\nToggled String is    \n %s",str);
getch();
}

Program 14: Program to Enter Data into Numeric Array and Sort it using Bubble Sort Technique and then display the Sorted Data
main()
{
int num[10],i,j,c;
clrscr();

for(c=0;c<10;c=c+1)
{
printf("Enter Data:");
scanf("%d",&num[c]);
}
clrscr();

printf("Sorting and Showing Data");
getch();

for (i=0;i<10;i=i+1)
{
for(j=0;j<9;j=j+1)
{
if(num[j]>num[j+1])
{
c=num[j];
num[j]=num[j+1];
num[j+1]=c;
]
}
}
printf("Sorted Data is :");
for(i=0;i<10;i=i+1)
{
printf("%d       ",num[c]);
}
getch();
}

Program 15: Program to implement Selection Sort Technique
main()
{
// program is same as Bubble Sort


//sorting loop

for(i=0;i<9;i=i+1)
{
for(j=i+1;j<8;j=j+1)
{
if(num[i]>num[j])
{
c=num[i];
num[i]=num[j];
num[j]=c;
}
}
}
// rest of the program is same as bubble sort

}

Program 16: Program to calculate Sum of all Elements , highest, lowest from numeric integer array

main()
{
int num[10],c,sum,max,min;
clrscr();
for(c=0;c<10;c=c+1)
{
printf("Enter Data");
scanf(%d",&num[c]);
}
sum=0;max=num[0];min=num[0];

for(c=0;c<10;c=c+1)
{
sum=sum+num[c];
if(max<num[c])
max=num[c];
if(min>num[c])
min=num[c];
}
printf("\n SUm of all Elements = %d",sum);
printf("\n Highest from Array = %d",max);
printf("\n Lowest from Array = %d",min);

getch();
}


Program 17: Program to enter data in one dimensional array and display data with INDEX Value
main()
{
int num[50],c,n;
clrscr();
printf("How many Elements to be entered");
scanf("%d",&n);

if (n>50)
{
pritnf("Out of Range");
return;
}
for(c=0;c<n;c=c+1)
{
printf("Enter Data:");
scanf("%d",&num[i]);
}
for (c=0; c<n;c=c+1)
{
printf("Data as INDEX  %d  =  %d",c+1,num[c]);
printf("\n");
}
getch();
}

Program 18: Program to  Enter Data & other Operations on 2D Numeric Array
main()
{
int num[3][3],r,c;

int sum;
clrscr();
printf("Entering Data:");
getch();

for(r=0;r<3;r=r+1)
{
for(c=0;c<;c=c+1)
{
printf("Enter Number:");
scanf("%d",&num[r][c]);
}
}

clrscr();

printf("Showing Data");
getch();
printf("\n ROW MAJOR Order\n");
for(r=0;r<3;r=r+1)
{
for(c=0;c<3;c=c+1)
{
printf("  %d  ",num[r][c]);
}
}
printf("\n\n Column Major Order");
getch();
for(c=0;c<3;c=c=1)
{
for(r=0;r<;r=r+1)
{
printf("  %d", num[r][c]);
}
printf("\n");
}

clrscr();

printf("\n Calculating Row WIse Total");
getch();

for(r=0;r<3;r=r+1)
{
for(sum=0,c=0;c<3;c=c+1)
{
sum=sum+num[r][c];
}
printf("Total of Element of ROW %d  is %d  ",r+1,sum);
}
clrscr();
printf("Calculating Column wise total");
getch();
for(c=0;c<3;c=c+1)
{
for (sum=0,r=0;r<3;r=r+1)
{
sum=sum+num[r]c];
}
printf("\nTOtal of Elements of Column %d   is  %d",c+1,sum);
}
getch();
}

That's all with the implementation of basic C problem Solutions.
Do leave a comment about how much you find it helpful and if there's any other question for which you want detailed Description and Solution

Have a Nice Reading Session ................... n ENJOY READING

Comments

Popular posts from this blog

Understanding Working of Text & Binary File in C

List of C Programs that makes u understand concepts in an easy fashion(Part1)

Starting C : A series of Chapters to learn C