C programs with explanation

C programme is divisible by 7 or not

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the value:");
scanf("%d",&a);
if(a%7==0){
printf("it is divisable with 7");}
else{
printf("it is not divisable with 7");}
getch();

}

C programme for given number is valid or not 

#include<stdio.h>
#include<conio.h>
void main(){
int a;
clrscr();
printf("Enter the password:");
scanf("%d",&a);
if(a=>1000&&a<=9999){
printf("password is valid");
}
else{
printf("password is invalid");
}
getch();
}

Result:
0000 is not valid
1010 is valid

C programme for addition

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,s;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
s=a+b;
printf("sum=%d",s);
getch();
}

C programme for subtraction

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,s;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
s=a-b;
printf("sum=%d",s);
getch();
}

C programme for division

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float c;
printf("Enter the values for division : ");
scanf("%d%d",a,b);
c=a/(b*1.0);
Printf ("Division result is : */*d "c);
getch();
}
Result
Enter the values for division: 13 15
Division result is :
Explanation
When we typed two values it will store in &a,&b scanf is used for read the from user entered data
Printf is used for display the result values

C programme for matrix

#include<stdio.h>
#include<conio.h>
void main(){
int i,n;clrscr();
printf("enter the n vaues");
scanf("%d",&n);
for(i=1;i<=9;i++);{
printf("%d*%d=%d",i,n,n*i);}
getch();
}

C programme for Multiplication of matrix

/*Multiplication of matrix*/
#include <stdio.h>
void main ()
{
int a[5][5], b[5][5], c[5][5], i, j, k, sum = 0, m, n, o, p;
printf("\nEnter the row and column of first matrix");
scanf("%d %d", &m, &n); printf("\nEnter the row and column of second matrix");
scanf("%d %d", &o, &p);
if (n != o) { printf("Matrix mutiplication is not possible"); printf("\nColumn of first matrix must be same as row of second matrix");
}
else { printf("\nEnter the First matrix: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &a[i][j]);
}
}
printf("\nEnter the Second matrix: "); for (i = 0; i < o; i++) { for (j = 0; j < p; j++) {
scanf("%d", &b[i][j]);
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < p; j++) {
c[i][j] = 0;
for (i = 0; i < m; i++) { //row of first matrix {
for (j = 0; j < p; j++) { //column of second matrix {
sum = 0;
for (k = 0; k < n; k++) {
sum = sum + a[i][k] * b[k][j];
}
c[i][j] = sum;
}
}
}
}
}
}
printf("\nThe multiplication of two matrix is\n");
for (i = 0; i < m; i++) {
printf("\n"); for (j = 0; j < p; j++) { printf("%d\t", c[i][j]);
    }
   }
}

C programme for reminder

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the value");
scanf("%d%d",&a,&b);
c=a%b;
printf("remender is %d",c);
getch();
}

C programme for upper triangle

#include<stdio.h>
#include<conio.h>
void main(){
int a[10][10],r1,c1,i,j;
clrscr();
printf("Enter the rows and colums for matrix:\n");
scanf("%d%d",&r1,&c1);
if(r1<=10&&c1<=10){
printf("Enter the values: ");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n Upper Triangle is ");
printf("\n");
for(i=0;i<r1;i++){
for(j=0;j<c1;j++){
if(i<=j)
printf("%d",a[i][j]);
else
printf("0");
}
printf("\n");
}
}
getch();
}

C Programme for loyer triangle

#include<stdio.h>
#include<conio.h>
void main(){
int a[10][10],r1,c1,i,j;
clrscr();
printf("Enter the rows and colums for matrix:\n");
scanf("%d%d",&r1,&c1);
if(r1<=10&&c1<=10){
printf("Enter the values: ");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
printf("\n Upper Triangle is ");
printf("\n");
for(i=0;i<r1;i++){
for(j=0;j<c1;j++){
if(i<=j)
printf("%d",a[i][j]);
else
printf("0");
}
printf("\n");
}
}
getch();
}

C programme to print maximum and minimum

#include<stdio.h>
#include<conio.h>
void main(){
int a[10],i,max,min;
clrscr();
printf("Enter any 10 values:");
for(i=0;i<10;i++){
scanf("%d",&a[i]);
min=max=a[0];
}
for(i=0;i<10;i++){
if(max<a[i]){
min=a[i];
}
if(min>a[i]){
min=a[i];
}
}
printf("Min and max num %d %d",min,max);
getch();

Result is


C programme for sum of given numbers using array

#include<stdio.h>
#include<conio.h>
void main(){
int a[5],i,sum=0;
clrscr();
printf("Enter any 5 values:");
for(i=0;i<5;i++){
scanf("%d",&a[i]);
}
for(i=0;i<5;i++){
sum=sum+a[i];
}
printf("sum=%d",sum);
getch();
}

C programme for print numbers reverse

#include<stdio.h>
#include<conio.h>
void main(){
int a[5],i;
clrscr();
printf("Enter any 5 values:");
for(i=0;i<5;i++){
scanf("%d",&a[i]);
}
for(i=4;i>=0;i--){
printf("%d\n",a[i]);
}
getch();
}

Comments

Popular posts from this blog

Awk command with simple examples

Learn Linux in Telugu | Linux complete Free Course in Telugu by 7Hills

rsync Command Examples | rsync Command In Telugu