Tuesday, 31 July 2018

C Program To Find Mode Value In Array

                    Finding Mode Value In Array

#include <stdio.h>

int mode(int arr[], int size); // function prototype

int main(void){
// in following simple program we will create a function which will accept an array as an input
// Furthermore that function will return mode value from the array elements
// mode value is the most repeated value of the elements
int arrayName[10] = {2,4,4,4,1,2,3,4,2,3}; // defined an array with 10 elements
//output each element of array
printf("Original values of the array\n\n");
printf("Array index\t\t\tValue\n");
for(int j=0; j<10; j++){
printf("%11d\t\t\t%4d\n", j, arrayName[j]);
}
int a = mode(arrayName, 10); // function call
printf("\n\nMode Value is: %d", a);
return 0;
}

//function definition
int mode(int arr[], int size){
int freq[size] = {0};
for(int i=0; i<size; i++){
freq[arr[i]]++;
}
printf("\nFrequency of each array element\n\n");
printf("Array index\t\t\tValue\n");
for(int j=0; j<10; j++){
printf("%11d\t\t\t%4d\n", j, freq[j]);
}
int largest = 0;
for (int j=0; j<size; j++){
if(freq[j]>freq[largest]){
largest = j;
}
}
printf("\nFrequency of each array element (graphical representation)\n\n");
printf("Array index\t\t\tFrequency\n");
for(int i=0; i<size; i++){
printf("%11d\t\t\t",i);
for(int j=0; j<freq[i]; j++){
printf("*");
}
printf("\n");
}
return largest;

}OUTPUT:-

          0                        0
          1                        1
          2                        3
          3                        2
          4                        4
          5                        0
          6                        0
          7                        0
          8                        0
          9                        0

Frequency of each array element (graphical representation)

Array index                     Frequency
          0
          1                     *
          2                     ***
          3                     **
          4                     ****
          5
          6
          7
          8
          9


Mode Value is: 4

Thursday, 26 July 2018

Sum of Array In C Language


SUM OF ARRAY IN C LANGUAGE:-

#include<stdio.h>
int sum(int a[],int s);
int main()
{
int add;
int s=10;
int arr[s]={1,1,1,1,1,1,1,1,1,1};
int ary[s]={1,1,1,1,1,1,1,1,1,1};
add=sum(arr,s)+sum(ary,s);
printf("Sum of these array=%d",add);
return 0;
}
int sum(int a[],int s)
{
int sum,i;
sum=0;
for(i=0;i<s;i++)
{
sum=sum+a[i];
}

}

OUTPUT:-

Sum of these array=20

Sunday, 22 July 2018

C++ Program Classes Simple Example

Basically These are the Simple Example of  Classes in C++ Program

EXAMPLE:1

#include<iostream>
#include<conio.h>
using namespace std;
class myclass
{
private:
int a,b,c;
public:
void myfun()

{

a=10;
b=20;
c=a+b;
cout<<"Result is:"<<c;
}
};
int main()
{
        myclass obj;
obj.myfun();
getch();
return 0;

}
OUTPUT:-

Result is:30

EXAMPLE:-2

#include<iostream>
#include<conio.h>
using namespace std;
class myclass
{
public:
void myfun(int a,int b)
{
int c;
c=a+b;
cout<<"Result is:"<<c;
}
};
int main()
{
myclass obj;
obj.myfun(100,50);
getch();
return 0;
}
OUTPUT:-

Result is:150

Friday, 20 July 2018

C Program Array Example Multiply by index value

ARRAY EXAMPLE IN C:-

information of this program basically header file include stdio.h then start the main function array declared size is equal to 10 defined an array with 10 element then print function use show screen in original values of array then for loop used initial value in 0 for loop exceute in less then 10 then  array index values multiply by 5 then show the result

CODE:-

#include <stdio.h>

int main(void){
// array is a type of variable which can store multiple items of the same data type
// in following simple program we will define an array of 10 elements
//After that we will multiply each element of array with 5 and then we will output the value of each element of the array

int arrayName[10] = {1,2,3,4,5,6,7,8,9,10,}; // defined an array with 10 elements

//output each element of array
printf("Original values of the array\n\n");
printf("Array index\t\t\tValue\n");
for(int i=0; i<10; i++)
{
printf("%11d\t\t\t%4d\n", i, arrayName[i]);
}

//output each element of array
printf("\n\nValues of the array after multiplication\n\n");
printf("Array index\t\t\tValue\n");
for(int i=0; i<10; i++)
{
arrayName[i] = arrayName[i] * 5;
printf("%11d\t\t\t%4d\n", i, arrayName[i]);
}


return 0;
}

Friday, 13 July 2018

C++ Program Ask To The User To Enter The Marks Obtained In 3 Subjects To Calculate and Display the Percentage Marks and Grade:

C++ Program Result card Sum,Percentage,Grade

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int sum,eng,math,bio,grade,percentage;
cout<<"Enter The marks of Eng:";
cin>>eng;
cout<<"Enter the marks of Math:";
cin>>math;
cout<<"Enter the marks of bio:";
cin>>bio;
sum=eng+math+bio;
cout<<sum;
percentage=(sum*100)/300;
cout<<endl<<percentage;
cout<<endl<<"Grade:";
if(percentage>=80)
{
cout<<"A";
}
else if(percentage>=70)
{
cout<<"B+";
}
else if(percentage>=60)
{
cout<<"B";
}
else if(percentage>=50)
{
cout<<"C";
}
else
{
cout<<"You are Failed";

}
cout<<endl<<"Thanks";
}

OUTPUT:-

Enter The marks of Eng:77
Enter the marks of Math:77
Enter the marks of bio:66
220
73
Grade:B+
Thanks

C++ Program Add,Product,Multipy


C++ Program Add,Product,Subtract:-

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b,c,sum,product,suntract;
a=10;
b=50;
c=a+b;
cout<<"SUM:";
cout<<c;
c=a*b;
cout<<endl<<"Product:";
cout<<c;
c=a-b;
cout<<endl<<"Subtract:";
cout<<c;

}
OUTPUT:-

SUM:60
Product:500
Subtract:-40

Wednesday, 11 July 2018

For Loop In C Programming Language


FOR LOOP INFORMATION:-

C Programming for LoopLoops are used in programming to repeat a specific block of code. After reading this tutorial, you will learn to create a for loop in C programmingLoops are used in programming to repeat a specific block until some end condition is met.


Example Of  For Loop:-


::