0% found this document useful (0 votes)
2 views9 pages

Document

C programming basic programs

Uploaded by

jonadany2390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Document

C programming basic programs

Uploaded by

jonadany2390
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Program 1

#include <stdio.h>

int main()

int m,n,i,j;

printf("Specify the number of rows: ");

scanf("%d",&m);

printf("specify the number of columns: ");

scanf("%d",&n);

int A[m][n];

printf("Enter the elements row wise: ");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&A[i][j]);

printf("\n");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

printf("%d ",A[i][j]);

printf("\n");

}
return 0;

}
Program 2

#include <stdio.h>

int main()

int m,n,i,j,sum;

printf("Specify the number of rows: ");

scanf("%d",&m);

printf("specify the number of columns: ");

scanf("%d",&n);

int A[m][n];

printf("Enter the elements row wise: ");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&A[i][j]);

printf("\n");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

printf("%d ",A[i][j]);

printf("\n");

}
int X[m],Y[n];

for(i=0;i<m;i++)

X[i] = 0;

for (j=0; j<n;j++)

X[i] =X[i]+ A[i][j];

if(i==0)

Y[j] = 0;

Y[j] =Y[j]+ A[i][j];

printf("\nRow sums upto: ");

for (i = 0; i < m; i++)

printf("%d ",X[i]);

printf("\n");

printf("Column total sums upto: ");

for (j=0;j<n;j++)

printf("%d ", Y[j]);

printf("\n");

return 0;

}
Program 3

#include <stdio.h>

int main()

int m,n,i,j;

printf("Specify the number of rows: ");

scanf("%d",&m);

printf("specify the number of columns: ");

scanf("%d",&n);

int A[m][n];

printf("Enter the elements row wise: ");

for(i=0;i<m;i++)

for(j=0;j<n;j++)
{

scanf("%d",&A[i][j]);

printf("\n");

for(i=0;i<m;i++)

for(j=0;j<n;j++)

printf("%d ",A[i][j]);

printf("\n");

int Sum = 0;
for (i = 0; i < m; i++) {

Sum += A[i][i];

printf("Sum of the primary diagonal: %d\n",Sum);

return 0;

}
Program 4

#include <stdio.h>

int Primecheck(int n);

int main() {

int num, flag;

printf("Input a number: ");

scanf("%d", &num);

flag = Primecheck(num);

if (flag == 0) {

printf("Prime\n");

} else {

printf("Not prime\n");

return 0;

int Primecheck(int n) {

if (n <= 1) return 1;

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) {

return 1;

return 0;

You might also like