اكتب برنامج C للعثور على طول سلسلة دون استخدام مكتبة الدالة

  • برمجة
  • برمجة سي c

اكتب برنامج C للعثور على طول سلسلة دون استخدام مكتبة الدالة

الخرج المتوقع :

Find the length of a string:
 -------------------------------------
Input a string : welcome
The string contains 7  number of characters.
So, the length of the string welcome is : 7

الأجوبة

/*Write a C program to find the length of a string without using the library function*/

#include <stdio.h>
#include <string.h>

 
void main()
{
    char str1[50];
    int i, l = 0;

       printf("\n\nFind the length of a string:\n ");
       printf("-------------------------------------\n");
 
    printf("Input a string : ");
    scanf("%s", str1);
 
    for (i = 0; str1[i] != '\0'; i++)
    {
        l++;
    }
    printf("The string contains %d  number of characters. \n",l);
    printf("So, the length of the string %s is : %d\n\n", str1, l);
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...