0% found this document useful (0 votes)
14 views

Lab Report

The document contains 27 programming problems involving various programming concepts like loops, arrays, conditional statements, functions etc. Each problem provides the question statement and the C code to solve the problem. The problems cover basic concepts like printing patterns using loops, finding even/odd numbers, checking voter eligibility etc. and more advanced concepts like 2D arrays, matrix operations, string handling etc.

Uploaded by

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

Lab Report

The document contains 27 programming problems involving various programming concepts like loops, arrays, conditional statements, functions etc. Each problem provides the question statement and the C code to solve the problem. The problems cover basic concepts like printing patterns using loops, finding even/odd numbers, checking voter eligibility etc. and more advanced concepts like 2D arrays, matrix operations, string handling etc.

Uploaded by

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

Nested loop

1 )“write a program to print the following pattern using


for loop”
12345

1234

123

12

#include<stdio.h>

void main(){

int i, j ;

for(i=5;i>=1;i--){

for(j=1;j<=i;j++){

printf("%d \t",j);

printf("\n");

}
}

2) "write a program to display the following pattern using for


loop"
5

44

333

2222

11111

#include<stdio.h>

#include<conio.h>

void main(){

int i,j;

for(i=5;i>=1;i--){

for(j=5;j>=i;j--){

printf("%d \t",i);

printf("\n");

}
3) write a program to display even numbers from (100 - 1 ) (forloop)

#include<stdio.h>

#include<conio.h>

void main(){

int i=100,k;

for(i=100;i>=1;i--){

printf("%d \n",i);

i=i-k;

While loop

4) write a program to display even numbers from 1-100

#include<stdio.h>

void main(){

int i=1;

while(i<=5){
printf("%d \n",i);

i=i+1;

5) write a program to display even numbers from 1-100

#include<stdio.h>

void main(){

int i=2,k=2;

while(i<=100){

printf("%d \n",i);

i=i+k;

6) write a program to display odd numbers from 1-100

#include<stdio.h>

void main(){

int i=1,k=2;

while(i<=100){

printf("%d \n",i);
i=i+k; }

Do while loop

7) write a program to display odd numbers from 1-100

#include<stdio.h>

void main(){

int i=1,k=2;

do{

printf("%d \n",i);

i=i+k ;

while(i<=5);

8) write a program to display even numbers from 1-100

#include<stdio.h>

void main(){

int i=2,k=2;

do{
printf("%d \n",i);

i=i+k;

while(i<=100);

9) write a program to display 15 natural numbers using the do while loop.

#include<stdio.h>

void main(){

int i=1,k;

do{

printf("%d \n",i);

i=i+k;

while(i<=15);

If else

10) write a program to check voter the person is voter or not

#include<stdio.h>

void main(){

int a;

printf("enter your age :");


scanf("%d",& a);

if(a>=18){

printf("you are voter");

else{

printf("'you are not voter");

11) write a program to display whether a student is brilliant or not

#include<stdio.h>

void main(){

int a;

printf("enter your mark :");

scanf("%d",& a);

if(a>=540){

printf("you are billiant student ");

else{

printf("you are average student");

}
12) write a program to check wether you are able to come at party or not.

#include<stdio.h>

void main(){

int a;

printf("enter your age :");

scanf("%d",& a);

if(a>=19){

printf("you are allow in party ");

else{

printf("you are allow in party");

If statement
13) write a program to check even or not

#include<stdio.h>

void main(){

int a;

printf("enter a number:");

scanf("%d",& a);

if(a%2==0){
printf("the number is even");

14) write a program to check odd or not

#include<stdio.h>

void main(){

int a;

printf("enter a number:");

scanf("%d",& a);

if(a%2==0){

else{

printf("the number is odd");

15) write a program to display whether the person is old or not

#include<stdio.h>

void main(){

int a;
printf("enter a age :");

scanf("%d",& a);

if(a>=50){

printf("you are old");

If else if statement

16) write a program to check whether score you got.

#include<stdio.h>

void main(){

int i;

printf("enter your mark:");

scanf("%d",& i);

if(i>=540 && i<=600){

printf("you score A+");

else if(i<=450 && i>=250) {

printf("you score A");

else{

printf("you score B+");


}

17) write a program to check whether the character is a vowel or not

#include<stdio.h>

void main(){

char i;

printf("enter your character:");

scanf("%c",& i);

if(i='a'||'e'||'i'||'o'||'u'){

printf("the character is vowel");

else if(i='A'||'E'||'I'||'O'||'U ') {

printf("the character is vowel");

else{

printf("the character is constant");

18) //write a program to check wheather the triangle is scalen, isoceles or


equlator
#include<stdio.h>

void main(){

int i,j,l;

printf("enter side of triagle:");

scanf("%d",& i);

printf("enter side of triagle:");

scanf("%d",& j);

printf("enter side of triagle:");

scanf("%d",& l);

if(i==j==l){

printf("triangle is equlator");

else if(i==j||i==j||j==l){

printf("triangle is isoceles");

else{

printf("the triangle is scalen");

For loop
19) write a program to calculate multiple of 5
#include<stdio.h>

void main(){

int i,j=5,l=5;

for( i=1;i<=10;i++){

printf("%d * %d = %d \n",l,i,j);

j=j+l;

printf("\n");

20) write a program to display natural numbers up to 20

#include<stdio.h>

void main(){

int i;

for( i=1;i<=20;i++){

printf("%d \n",i);

21)

write a program to display odd numbers up to 20


#include<stdio.h>

void main(){

int i,j=1;

for( i=1;i<=20;i++){

printf("%d \n",i);

i=i+j;

Single dimension array

22)

//write a program to store 10 student namesand display them

#include<stdio.h>

void main(){

char name[20][10];

int i;

for( i=0;i<10;i++){

printf("enter name:");

scanf("%sdf",& name[i]);
}

for( i=0;i<10;i++){

printf("%s \n",name[i]);

23)

write a program to store 10 student ph number and display them

#include<stdio.h>

void main(){

int n[20];

int i;

for( i=0;i<10;i++){

printf("enter phone number:");

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

for( i=0;i<10;i++){

printf("%d \n",n[i]);
}

24) write a program to store 20 student addresses and display them

#include<stdio.h>

void main(){

char n[20][20];

int i;

for( i=0;i<10;i++){

printf("enter address:");

scanf("%s",& n[i]);

for( i=0;i<10;i++){

printf("%s \n",n[i]);

Two-dimension array
25) write a program to display 2*2 matrix

#include<stdio.h>

void main(){

int a[2][2];

int i,j;

for(i=0;i<2;i++){

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

printf("enter a number :");

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

for(i=0;i<2;i++){

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

printf("%d \t",a[i][j]);

printf("\n");

26) //write a program to display 2*2 matrix of name

#include<stdio.h>
void main(){

char a[2][2];

int i,j;

for(i=0;i<2;i++){

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

printf("enter a name :");

scanf("%s",& a[i][j]);

for(i=0;i<2;i++){

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

printf("%s \t",a[i][j]);

printf("\n");

27)write as the program to display the sum of two (2*2) matrix

#include<stdio.h>

void main(){

int i,j,mat[2][2],matr[2][2],matri[2][2];
for(i=0;i<2;i++){

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

printf("enter the number for matrix :");

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

printf("\n");

printf("the matrix is");

printf("\n");

for(i=0;i<2;i++){

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

printf("%d \t",mat[i][j]);

printf("\n");

for(i=0;i<2;i++){

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

printf("enter the number for matrix :");

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

printf("\n");

printf("the matrix is");

printf("\n");

for(i=0;i<2;i++){

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

printf("%d \t",mat[i][j]);

printf("\n");

printf("\n");

for(i=0;i<2;i++){

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

matri[i][j]=mat[i][j]+matr[i][j];

for(i=0;i<2;i++){
for(j=0;j<2;j++){

printf("%d \t",matri[i][j]);

printf("\n");

You might also like