Docsity
Docsity

Pripremite ispite
Pripremite ispite

Studirajte zahvaljujući brojnim resursima koji su dostupni na Docsity-u


Nabavite poene za preuzimanje
Nabavite poene za preuzimanje

Zaradite bodove pomažući drugim studentima ili ih kupite uz Premium plan


Školska orijentacija
Školska orijentacija


Vežbe iz programiranja u C jeziku, Vežbe od Informatika

exercisesc programming exercises to help you understand loops

Tipologija: Vežbe

2018/2019

Učitan datuma 26.05.2019.

serda
serda 🇦🇱

5

(1)

1 dokument

1 / 6

Toggle sidebar

Ova stranica nije vidljiva u pregledu

Ne propustite važne delove!

bg1
1. Write a program in C to display the first 10 natural numbers.
#include <stdio.h>
void main()
{
int i;
printf("The first 10 natural numbers are:\n");
for (i=1;i<=10;i++)
{
printf("%d ",i);
}
printf("\n");
}
2. Write a C program to find the sum of first 10 natural numbers.
#include <stdio.h>
void main()
{
int j, sum = 0;
printf("The first 10 natural number is :\n");
for (j = 1; j <= 10; j++)
{
sum = sum + j;
printf("%d ",j);
}
printf("\nThe Sum is : %d\n", sum);
}
3. Write a program in C to display n terms of natural number and their sum.
#include <stdio.h>
void main()
{
int i,n,sum=0;
printf("Input Value of terms : ");
scanf("%d",&n);
printf("\nThe first %d natural numbers are:\n",n);
for(i=1;i<=n;i++)
{
printf("%d ",i);
sum+=i;
}
printf("\nThe Sum of natural numbers upto %d terms : %d \n",n,sum);
}
4. Write a program in C to display the cube of the number upto given an integer.
#include <stdio.h>
void main()
{
int i,ctr;
printf("Input number of terms : ");
scanf("%d", &ctr);
for(i=1;i<=ctr;i++)
{
printf("Number is : %d and cube of the %d is :%d \n",i,i, (i*i*i));
}
pf3
pf4
pf5

Delimični pregled teksta

Preuzmite Vežbe iz programiranja u C jeziku i više Vežbe u PDF od Informatika samo na Docsity!

1. Write a program in C to display the first 10 natural numbers.

#include <stdio.h> void main() { int i; printf("The first 10 natural numbers are:\n"); for (i=1;i<=10;i++) { printf("%d ",i); } printf("\n"); }

2. Write a C program to find the sum of first 10 natural numbers.

#include <stdio.h> void main() { int j, sum = 0;

printf("The first 10 natural number is :\n");

for (j = 1; j <= 10; j++) { sum = sum + j; printf("%d ",j); } printf("\nThe Sum is : %d\n", sum); }

3. Write a program in C to display n terms of natural number and their sum.

#include <stdio.h> void main() { int i,n,sum=0; printf("Input Value of terms : "); scanf("%d",&n); printf("\nThe first %d natural numbers are:\n",n); for(i=1;i<=n;i++) { printf("%d ",i); sum+=i; } printf("\nThe Sum of natural numbers upto %d terms : %d \n",n,sum);

}

4. Write a program in C to display the cube of the number upto given an integer.

#include <stdio.h> void main() { int i,ctr; printf("Input number of terms : "); scanf("%d", &ctr); for(i=1;i<=ctr;i++) { printf("Number is : %d and cube of the %d is :%d \n",i,i, (iii));

5. Write a program in C to read 10 numbers from keyboard and find their sum and average.

#include <stdio.h> void main() { int i,n,sum=0; float avg; printf("Input the 10 numbers : \n"); for (i=1;i<=10;i++) { printf("Number-%d :",i);

scanf("%d",&n); sum +=n; } avg=sum/10.0; printf("The sum of 10 no is : %d\nThe Average is : %f\n",sum,avg);

}

6. Write a program in C to display the multiplication table of a given integer.

#include <stdio.h>

void main()

int j,n;

printf("Input the number (Table to be calculated) : ");

scanf("%d",&n);

printf("\n");

for(j=1;j<=10;j++)

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

7. Write a program in C to display the multipliaction table vertically from 1 to n.

#include <stdio.h> void main() { int j,i,n; printf("Input upto the table number starting from 1 : "); scanf("%d",&n); printf("Multiplication table from 1 to %d \n",n); for(i=1;i<=10;i++) { for(j=1;j<=n;j++) { if (j<=n-1) printf("%dx%d = %d, ",j,i,ij); else printf("%dx%d = %d",j,i,ij);

printf("\n");

10. Write a program in C to display the pattern like right angle triangle with a number

#include <stdio.h> void main() { int i,j,rows; printf("Input number of rows : "); scanf("%d",&rows); for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) printf("%d",j); printf("\n"); } }

11. Write a program in C to make such a pattern like right angle triangle with a number which will repeat a

number in a row.

#include <stdio.h> void main() { int i,j,rows;

printf("Input number of rows : "); scanf("%d",&rows); for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) printf("%d",i); printf("\n"); } }

12. Write a program in C to make such a pattern like right angle triangle with number increased by 1.

#include <stdio.h> void main() { int i,j,rows,k=1; printf("Input number of rows : "); scanf("%d",&rows); for(i=1;i<=rows;i++) { for(j=1;j<=i;j++) printf("%d ",k++); printf("\n"); }

13. Write a program in C to make such a pattern like a pyramid with numbers increased by 1.

#include <stdio.h> void main() { int i,j,spc,rows,k,t=1; printf("Input number of rows : "); scanf("%d",&rows); spc=rows+4-1; for(i=1;i<=rows;i++) { for(k=spc;k>=1;k--) { printf(" "); } for(j=1;j<=i;j++) printf("%d ",t++); printf("\n"); spc--; } }

14. Write a program in C to make such a pattern like a pyramid with an asterisk.

#include <stdio.h> void main() { int i,j,spc,rows,k; printf("Input number of rows : "); scanf("%d",&rows); spc=rows+4-1; for(i=1;i<=rows;i++) { for(k=spc;k>=1;k--) { printf(" "); }

for(j=1;j<=i;j++) printf("* "); printf("\n"); spc--; } }

15. Write a C program to calculate the factorial of a given number.

#include <stdio.h> void main(){ int i,f=1,num;

printf("Input the number : ");